Given:
and
What is the result?
Given:
and
What is the result?
When the ConSub object is instantiated with the value 4, the ConSub(int a) constructor is called, printing '4'. Since there are no chained calls within ConSub(int a), no other constructors in ConSub are invoked. However, this constructor implicitly calls the superclass (ConSuper) constructor. The corresponding ConSuper(int a) constructor then prints '2'. The output is therefore '234', as the ConSuper() prints '3' after calling ConSuper(int a) with 'this(2)'.
Correct answer is C
answer: C Automatic invocation of a superclass constructor must be the first line in the subclass constructor. Doesn't matter parameterized or not. //default constructor not inserted class ConSub ConSub() { this(4) } //default constructor is inserted ConSub(int a) { System.out.println(a); } //default constructor not inserted // default class ConSuper - ok // protected constructor - ok class ConSuper { protected ConSuper() { this(2); System.out.println("3"); } //default constructor is inserted class ConSuper { protected ConSuper(int a) { System.out.println(a); } Object default constructor >2 >23 >234
C is correct
Tested : C
Tested: C.
C is correct Tested