Given:
class X {}
class Y {Y () {}}
class Z {z(int i ) {} }
Which class has a default constructor?
A.
X only
B.
Y only
C.
Z only
D.
X and Y
E.
Y and Z
F.
X and Z
G.
X, Y and Z
Given:
class X {}
class Y {Y () {}}
class Z {z(int i ) {} }
Which class has a default constructor?
Given:
class X {}
class Y {Y () {}}
class Z {z(int i ) {} }
Which class has a default constructor?
A.
X only
B.
Y only
C.
Z only
D.
X and Y
E.
Y and Z
F.
X and Z
G.
X, Y and Z
I think Answer is “A”
A.
X only
I think the answer is either ‘A’ or ‘F’.
Here’s my rationale :
In the previous version of this exam among the comments, one of them said that the lower-case ‘z’ was a typo and it should be Uppercase ‘Z’ which would therefore make the answer be ‘A’.
But if there is no typo and the lower-case ‘z’ remains, than ‘F’ is the answer because Z(int i) is not a default constructor.
*cont.*
…whereas z(int i) is not of Class Z so therefore no constructor is user-defined and Java will create a default one as a result.
However, z(int i) won’t compile since it does not declare return value (e.g., void).
return “type”.
I think is a typo in class Z, and must be a correct constructor Z(int i). Only constructors have not return type.