Question 14
class A extends
Thread {
public A(Runnable r) {super(r);}
public void run() {System.out.print("A");}
}
class B implements Runnable {
public void run() {System.out.print("B");}
}
class C {
public static void main(
String[] args) {
new A(new B()).start();
}
}
What is the result of attempting to compile and run the program?
a. Prints: A
b. Prints: B
c. Prints: AB
d. Prints: BA
e. Compiler error
f. Run time error
g. None of the above
The answer is a. But I don't understand why isn't B's run is being executed. However if i remove A's run method B's run method is run. I guess that A's run is overridding B's run. How this overriding takes place.
[ May 17, 2003: Message edited by: Anupam Sinha ]