File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
soujanya Bugatha
Greenhorn
Posts: 10
  • 0
  • 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
  • 0
  • 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"
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic