This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
soujanya Bugatha
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The output of this program is "BeginRunEnd" can anyone explain this to me?


public class Cruiser implements Runnable {
public static void main(String[] args) throws InterruptedException {
Thread a = new Thread(new Cruiser());
a.start();

System.out.print("Begin");
a.join();
System.out.print("End");
}

public void run() {
System.out.print("Run");
}
}
 
Rahul mir
Ranch Hand
Posts: 38
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Start() starts the thread by calling its run() method.
Here, after start method call print statement will Print "Begin", after that compiler go for run() method, Thread is still not started, so a.join() will execute after run() method and the final result will be "BeginRunEnd"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic