Discussion
Sample84 is run - what will be the output?
public class Sample84 extends Thread
{
private final String tag;
Sample84(String tag)
{
this.tag = tag;
}
public void run()
{
System.out.print(tag + " ");
}
public static void main(String[] args) throws InterruptedException
{
Thread t = new Sample84("sub");
t.start();
t.join();
System.out.print("main");
}
}
Answer: D
Correct answer: sub main
t.start() begins the subclass’s run, which prints sub, and t.join() blocks main until it has finished. Only then does main print. Without the join the order would be genuinely indeterminate, which is what the “either order” option describes - and it is exactly what join exists to prevent.
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