Java SE 7 Programmer I — Question 31

Given:
class X {}
class Y { Y ( ) { } }
class Z { Z (int i ) { } }
Which class has a default constructor?

Answer options

Correct answer: A

Explanation

Class X has a default constructor because it does not define any constructors, thus Java provides one automatically. Class Y has a default constructor since it explicitly defines one without parameters. However, class Z does not have a default constructor because it requires an integer parameter, making option A the only correct choice.