Discussion
Sample07 is run - what will be the output?
public class Sample07 extends Thread
{
public void run() { }
public static void main(String[] args) throws InterruptedException
{
Sample07 job = new Sample07();
boolean before = job.isAlive();
job.start();
job.join();
System.out.println(before + " " + job.isAlive());
}
}
Answer: C
A thread is alive only between being started and dying. Before start() it is NEW and not alive, and once join() has returned it has finished, so it is not alive either. The value would be true only if sampled while the thread was running, which is not a moment this program can name.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development