Java OCA OCP Practice Question 2590

Question

Consider the following program and predict the output:

class MyThread extends Thread {
     public MyThread(String name) {
             this.setName(name);
             start();//from w w w .  j ava  2 s .  c om
             System.out.println("in ctor " + getName());
    }
     public void start() {
             System.out.println("in start " + getName());
     }
     public void run() {
             System.out.println("in run " + getName());
     }
}

class Test {
     public static void main(String []args) {
             new MyThread("oops");
     }
}
a)  in start oops//from ww w  .  j  a  v a 2  s .co m
     in ctor oops

b)  in start oops
     in run oops
     in ctor oops

c)  in start oops
     in ctor oops
     in run oops

d)  in ctor oops
     in start oops
     in run oops


a)

Note

You have overridden the start() method, so the run() method is never called!




PreviousNext

Related