What will be the result of attempting to compile and run the following program?
class Extender extends Thread { public Extender() { } public Extender(Runnable runnable) {super(runnable);} public void run() {System.out.print("|Extender|");} } public class Implementer implements Runnable { public void run() {System.out.print("|Implementer|");} public static void main(String[] args) { new Extender(new Implementer()).start(); // (1) new Extender().start(); // (2) new Thread(new Implementer()).start(); // (3) }//from w w w.j a v a 2 s . c o m }
Select the one correct answer.
(b)
(1) results in the run()
method of the Extender class being called, which overrides the method from the Thread class, as does (2).
(3) results in the run()
method of the Implementer class being called.
Invoking the start()
method on a subclass of the Thread class always results in the overridden run()
method being called, regardless of whether a Runnable is passed in a constructor of the subclass.