wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructor Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Constructor Issue" Watch "Constructor Issue" New topic
Author

Constructor Issue

Micheal John
Ranch Hand

Joined: Nov 01, 2006
Posts: 344
From web page


The answer is given as c; why not a?


Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
The superclass may have a constructor other than a default constructor.

The following dummy code should make it clear:


Prints 5.


SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,

I don't agree with Aniket nor with the makers of this question.

a. is also correct.

They state:
a. The superclass must not have any constructor other than a default constructor.
should be wrong
But it is true.



this class has any (just one) constructor other than the default constructor, and so in the given scenario, the subclass would not compile.

if you put any constructor in a class, it simply does not have a default constructor.
The default constructor is only the "invisible" constructor, the compiler puts in, when you don't provide any.

The example that Aniket gave also has no default constructor, it has a parameterless constructor.

The makers of the test mixed up the terms "parameterless constructor" with "default constructor".

Language specification:
8.8.9 Default Constructor

If a class contains no constructor declarations, then a default constructor that takes no parameters is automatically provided: (...)



If choice a were
"The superclass must not have any constructor other than a parameterless constructor."
then it would be false.

Hopefully on the real exam you'll not find such wrong terminology.

Finally, there is one possibility when the code compiles, when the constructor you provide is the same as a default constructor would be - parameterless. But even then it should not be called "default constructor".



Yours,
Bu.


all events occur in real time
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218

The makers of the test mixed up the terms "parameterless constructor" with "default constructor".


So did I!

Guess a 12 hour workday doesen't help in answering questions...
 
 
subject: Constructor Issue