What is the result?
A. BD
B. DB
C. BDC
D. DBC
E. Compilation fails.
Answer:
E is correct. The implied super() call in Bottom2’s constructor cannot be satisfied because
there isn’t a no-arg constructor in Top. 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.
(Objective 1.6)
==
class Top { public Top(String s) { System.out.print("B"); } } public class Bottom2 extends Top { public Bottom2(String s) { System.out.print("D"); } public static void main(String [] args) { new Bottom2("C"); System.out.println(" "); } }
No comments:
Post a Comment