Will the following code ever print out the message In myMethod?
1. class MyClass extends Thread { 2. public void run() { 3. System.out.println("Running"); 4. System.out.println("Done"); 5. } // ww w . j a v a 2 s . c om 6. 7. private void myMethod() { 8. System.out.println("In myMethod"); 9. } 10. 11. public static void main(String args[]) { 12. MyClass myObject = new MyClass(); 13. myObject.myMethod(); 14. myObject.start(); 12. } 13. }
A.
The call to myMethod()
occurs before the thread is registered with the thread scheduler, so the object executes the method in the main thread.