It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

soujanya Bugatha
Greenhorn

Joined: May 29, 2012
Posts: 10
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

Joined: Oct 31, 2012
Posts: 38



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
 
subject: Threads
 
Similar Threads
Concurrency question
Thread question from www.scjptest.com
Help in a question about Threads
Threads Question
thread problem