About Question enthuware.ocpjp.v8.2.1291 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

About Question enthuware.ocpjp.v8.2.1291 :

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests