Given:
class MyBaseClass { public MyBaseClass(String s) { System.out.print("B"); } //from w w w . j av a2 s .c o m } public class MyClass extends MyBaseClass { public MyClass(String s) { System.out.print("D"); } public static void main(String [] args) { new MyClass("C"); System.out.println(" "); } }
What is the result?
A. BD B. DB C. BDC D. DBC E. Compilation fails
E is correct.
The implied super()
call in MyClass's constructor cannot be satisfied because there is no no-arg constructor in MyBaseClass.
A default, no-arg constructor is generated by the compiler only if the class has no constructor defined explicitly.
A, B, C, and D are incorrect based on the above.