1Z0-808 · Question #3
class A { public A(){ System.out.print ("A "); } } class B extends A{ public B(){ //line n1 System.out.print ("B "); } } class C extends B{ public C(){ //line n2 System.out.print ("C "); } public…
The correct answer is C. A B C. Option C (A B C) is correct because Java implicitly inserts a super() call as the first statement in any constructor that doesn't explicitly call super() or this(). So when new C() is invoked, C's constructor calls B's constructor, which calls A's constructor - execution then…
Question
Options
- AC B A
- BC
- CA B C
- DCompilation fails at line n1 and line n2
How the community answered
(29 responses)- A14% (4)
- B7% (2)
- C76% (22)
- D3% (1)
Explanation
Option C (A B C) is correct because Java implicitly inserts a super() call as the first statement in any constructor that doesn't explicitly call super() or this(). So when new C() is invoked, C's constructor calls B's constructor, which calls A's constructor - execution then unwinds back down the chain, printing "A", then "B", then "C".
Why the distractors are wrong:
- A (
C B A) reverses the order - constructors complete from top-down (ancestor first), not bottom-up. - B (
C) would only be true if child constructors could skip calling their parent - they cannot; the implicitsuper()is mandatory. - D (Compilation fails) is wrong because the implicit
super()insertion is done by the compiler automatically; neithern1norn2have any issue.
Memory tip: Think of it as "you can't exist before your parents" - Java always constructs the ancestry chain from the oldest ancestor (Object → A → B → C) before the child can finish initializing.
Topics
Community Discussion
No community discussion yet for this question.