Java Multiple Choice Questions & Answers on Thread class for Freshers

1. Which of these class is used to make a thread?

a) String
b) System
c) Thread
d) Runnable
Answer: c

Explanation: Thread class is used to make threads in java, Thread encapsulates a thread of execution. To create a new thread the program will either extend Thread or implement the Runnable interface.
2. Which of these interface is implemented by Thread class?

a) Runnable
b) Connections
c) Set
d) MapConnections
Answer: a
3. Which of these method of Thread class is used to find out the priority given to a thread?

a) get()
b) ThreadPriority()
c) getPriority()
d) getThreadPriority()
Answer: c
5. Which of these method of Thread class is used to Suspend a thread for a period of time?

a) sleep()
b) terminate()
c) suspend()
d) stop()
Answer: a
6. Which function of pre defined class Thread is used to check weather current thread being checked is still running?

a) isAlive()
b) Join()
c) isRunning()
d) Alive()
Answer:a

Explanation:isAlive() function is defined in class Thread, it is used for implementing multithreading and to check whether the thread called
upon is still running or not.
7. What is the output of this program?
  1.     class multithreaded_programing {
  2.         public static void main(String args[]) {
  3.             Thread t = Thread.currentThread();
  4.             t.setName("New Thread");
  5.             System.out.println(t);        
  6.         }
  7.     }
a) Thread[5,main] 
b) Thread[New Thread,5] 
c) Thread[main,5,main] 
d) Thread[New Thread,5,main] 

Answer: d
8. What is the priority of the thread in output of this program?
  1.     class multithreaded_programing {
  2.         public static void main(String args[]) {
  3.             Thread t = Thread.currentThread();
  4.             t.setName("New Thread");
  5.             System.out.println(t.getName());        
  6.         }
  7.     }
a) main
b) Thread
c) New Thread
d) Thread[New Thread,5,main]

Answer: c

Explanation: The getName() function is used to obtain the name of the thread, in this code the name given to thread is ‘New Thread’.
9. What is the name of the thread in output of this program?
  1.     class multithreaded_programing {
  2.         public static void main(String args[]) {
  3.             Thread t = Thread.currentThread();
  4.             System.out.println(t.getPriority());        
  5.         }
  6.     }
a) 0
b) 1
c) 4
d) 5
Answer: d

Explanation: The default priority given to a thread is 5.
10. What is the name of the thread in output of this program?
  1.     class multithreaded_programing {
  2.         public static void main(String args[]) {
  3.             Thread t = Thread.currentThread();
  4.             System.out.println(t.isAlive());        
  5.         }
  6.     }
a) 0
b) 1
c) true
d) false
Answer: c

Explanation: Thread t is seeded to currently program, hence when you run the program the thread becomes active & code ‘t.isAlive’ returns true.

Related

Computer Fundamentals Multiple choice Questions and Answers on FORTRAN Basics for Freshers

1. Which is interpreted language? a) C++b) Cc) MATLABd) Fortran Answer: c Explanation: MATLAB is an interpreted language. All the other languages are compiled languages. In the case of Interprete...

multiple choice Questions and Answers on Mobile Web Services of Cloud Computing

1. Which of the following is a push mechanism for publishing Web site data that is device-specific? a) WAPb) GPRSc) GAPd) None of the mentioned Answer: a Explanation: WAP stands for Wireless Acce...

Computer Fundamentals Multiple choice Questions and Answers on High Level Languages for Freshers

1. Prolog comes under ___________ a) Logic Programmingb) Procedural Programmingc) OOPd) Functional Answer: a Explanation: Prolog stands for Programming in Logic. The options mentioned are the fou...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item