JAVA Programming :: Threads - Discussion
Home > JAVA Programming > Threads > MCQs Questions Discussion
7 / 6
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");
}
}
Arun-test run-test
Brun-test
CCompilation fails due to an error on line 4
DCompilation fails due to an error on line 7
Answer: Option (Login/Signup)
Show Explanation
Asked In ::
STEP-BY-STEP
When the line t.run() is read, the run() method is executed as usual method call, and run-test is printed.
Until now, we have only one thread i.e, the main thread.
But, when the line t.start() is read, a new thread is created, i.e, Test thread.
The thread invokes the run() method and run-test is printed again.
Read Full Answer
Report Error
Please Login First Click Here