1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 112


Given:

and

What is the result?

Show Answer
Correct Answer: BC

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)'.

Discussion

6 comments
Sign in to comment
ObaltOption: C
Feb 8, 2023

Correct answer is C

StavokOption: C
Jul 19, 2023

C is correct Tested

OmnisumemOption: C
Sep 20, 2023

Tested: C.

TheOneAboveAllOption: C
Oct 15, 2023

Tested : C

d7bb0b2Option: C
Jan 11, 2024

C is correct

ASPushkinOption: C
Jun 2, 2024

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