Page 1 of 1

About Question enthuware.ocpjp.v8.2.1291 :

Posted: Sat Jul 09, 2016 9:20 pm
by johnlong
Hi

Please consider the following code
class A extends Thread{

public A(){}
public A(Runnable r){
}
public void run(){
System.out.println("Thread");}
}
public class Tge implements Runnable {

@Override
public void run() {
System.out.println("Runnable");
}

public static void main(String[] args) {

new A(new Tge()).start();
}
}
Output is different opposed to declaration
If a Thread is created with a Runnable, Thread class's run() method calls the run() method of the given Runnable.

Re: About Question enthuware.ocpjp.v8.2.1291 :

Posted: Sat Jul 09, 2016 9:58 pm
by admin
Please read the complete explanation. The rest of the explanation says, "So you would expect it to execute Threader's run() method. However, Pooler is overriding Thread class's run() method and so the default behavior of Thread's run() is lost."
This part explains why the default behavior of Thread class is not applicable here.