Q) Daemon thread runs in
- Background
- Foreground
- Both
- 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?
- setDaemon(boolean value)
- setThread(boolean value)
- createDaemon(boolean value)
- 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
- First thread setDaemon() is called then start()
- First thread start() is called then setDaemon()
- Call thread start() and setDaemon() in any order
- 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?
- Wait ()
- Sleep ()
- Join ()
- isAlive()
Answer:3
Q) Which will contain the body of the thread in Java?
- Start()
- Run()
- Main()
- 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 .