0

Possible Duplicate:
Java default constructor

I am working on Java practice questions and came across this :

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 would say that the correct answer would be A, because class X is the only class without any explicitly defined constructor. My peer is saying that it would be G, because a what constitutes a default constructor is when you actually change values within the constructor body.

We've done some research and answers seem to differ when it comes to what a default constructor actually IS (at this level).

Can anyone provide an answer and logical explanation here? Thank you very much.

Community
  • 1
  • 1
Eric T
  • 944
  • 1
  • 11
  • 26

1 Answers1

9

My peer is saying that it would be G, because a what constitutes a default constructor is when you actually change values within the constructor body.

I would say your peer is wrong here, at the language level. Section 8.8.9 of the JLS only uses the term "default constructor" to mean "the constructor provided by the compiler if no constructor is explicitly specified".

I wish this were spelled out more explicitly - and I also wish that C# used the same terminology :(

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194