Interview Questions

Output question 18.

Java Interview Questions and Answers (part 4)


(Continued from previous question...)

78. Output question 18.

class MyThread extends Thread {
public void run() {
System.out.println("1");
}
public void start(){
System.out.println("2");
}

}

public class MyClass {
public static void main(String[] args) {
MyThread thread1=new MyThread();
thread1.start();

}
}



Answer.
When we call start() method on thread, it internally calls run() method with newly created thread. So, if we override start() method, run() method will not be called until we write code for calling run() method.


/*OUTPUT
2
*/

(Continued on next question...)

Other Interview Questions