Welcome Guest | Sign in | Register
Threads - Discussion Page For Q.2949 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Threads > Questions and Answers

Q: What will happen when you attempt to compile and run the following code ?

1. public class Test extends Thread{
2. public static void main(String argv[]){
3. Test t = new Test();
4. t.run();
5. t.start();
6. }
7. public void run(){
8. System.out.println("run-test");
9. }
10. }
A. run-test run-test B. run-test
C. Compilation fails due to an error on line 4 D. Compilation fails due to an error on line 7

Answer and Explanation

Answer:run-test run-test

Explanation:
t.run() Legal, but does not start a new thread , it is like a method call of class Test BUT t.start() create a thread and call run() method.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.