Given the code fragment:
What is the result?
A. Jesse 25
Walter 52
B. Compilation fails only at line n1
C. Compilation fails only at line n2
D. Compilation fails at both line n1 and line n2
Given the code fragment:
What is the result?
A. Jesse 25
Walter 52
B. Compilation fails only at line n1
C. Compilation fails only at line n2
D. Compilation fails at both line n1 and line n2
Answer D:
Line n1 fails because there is no no-args constructor.
Line n2 fails because the code is calling the constructor by using the class name instead of this() keyword.
D
Yeah it’s D.
D is the answer. In line 1 this() does not work because when you create any constructor default constructor will be canceled; therefore you cannot call it by using this(). When line 1 is the problem, line2 is being the problem automatically