?
What will happen when you attempt to compile and run the following code?
What will happen when you attempt to compile and run the following code?
public class Test extends Thread{
public static void main(String argv[]){
Test t = new Test();
t.run();
t.start();
}
public void run(){
System.out.println("run-test");
}
}
public class Test extends Thread{
public static void main(String argv[]){
Test t = new Test();
t.run();
t.start();
}
public void run(){
System.out.println("run-test");
}
}
Answer & Solution
Correct Answer:
Option
A
t.run() Legal, but does not start a new thread , it is like a method call of a class Test BUT t.start() creates a thread and call run() method.
Join the Discussion
Login to post a comment or share your explanation.
Login