Q) Daemon thread runs in
  1. Background
  2. Foreground
  3. Both
  4. none

Answer: 1.
Notes: threads that run-in background within same process is called daemon thread. Read daemon thread with example in Java


Q) Which method is used to create a daemon thread?
  1. setDaemon(boolean value)
  2. setThread(boolean value)
  3. createDaemon(boolean value)
  4. makeDeamon(boolean value);

Answer : 1
Note: setDaemon(boolean value) – We pass parameter as “true” make thread as a daemon thread.


Q) To create a daemon thread
  1. First thread setDaemon() is called then start()
  2. First thread start() is called then setDaemon()
  3. Call thread start() and setDaemon() in any order
  4. All correct

Answer: 1.
To make a java thread daemon we need to call setDaemon method before start method


Q) Which method is used to wait for child threads to finish in Java?
  1. Wait ()
  2. Sleep ()
  3. Join ()
  4. isAlive()

Answer:3


Q) Which will contain the body of the thread in Java?
  1. Start()
  2. Run()
  3. Main()
  4. Execute()

Answer: 2
When we extend thread class or implement runnable interface, we override or implement run() method. When a thread is created and start the run() method get called. Read thread program example in java .


Related Posts