Which class has a default constructor?

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



Leave a Reply 6

Your email address will not be published. Required fields are marked *


Anil

Anil

I think Answer is “A”

A.
X only

lolwut?

lolwut?

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.

lolwut?

lolwut?

*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.

Tim

Tim

However, z(int i) won’t compile since it does not declare return value (e.g., void).

Tim

Tim

return “type”.

sc0r

sc0r

I think is a typo in class Z, and must be a correct constructor Z(int i). Only constructors have not return type.