Discussion
Sample48 is run - what will be the output?
public class Sample48
{
public static void main(String[] args) throws InterruptedException
{
Thread reporter = new Thread(new Runnable()
{
public void run() { System.out.print("work "); }
});
reporter.start();
for (int attempt = 0; attempt < 3; attempt++)
{
reporter.join();
}
System.out.print("done");
}
}
Answer: D
join on a thread that has already died returns at once, so joining three times is harmless and does not run the body again. Only start() is restricted to a single call; join may be made by any number of threads any number of times.
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