Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructor question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Constructor question" Watch "Constructor question" New topic
Author

Constructor question

Sumanth Shanbhag
Greenhorn

Joined: May 10, 2007
Posts: 13
Hi,

This question is straight from the KS&BB book.



I don't quite understand how the compilation fails as explained by the author. In Bottom2 the super() would be called, which would be a no-arg constructor to its parent class Top. But since Bottom2's constructor is already overridden with arguments matching the super class constructor there shouldn't be a problem with compilation at least. Correct me if i am wrong here please..
Mercurio Savedra
Greenhorn

Joined: Dec 04, 2005
Posts: 25
Hi friend, remember that if you dont write an explicit call to the super constructor with some arguments the compiler try to insert at he first line of the constructor a super no arg call, then reviewing the parent class there is not a no arg constructor so the compilaton process fail

got it?
Meena R. Krishnan
Ranch Hand

Joined: Aug 13, 2006
Posts: 178
Add "super(s);' as the first line of Bottom2's constructor and it will compile fine.
Michael Raymond Jr.
Ranch Hand

Joined: May 16, 2005
Posts: 178
I think in the K&B book they recommend to always create the default constructor if you are overloading it.


Scooby Snacks for everyone...<br /> <br />SCJA, SCJP 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructor question
 
Similar Threads
Questions
kathy sierra scjp 1.6 book question doubt
Self Test Question of K&B.
Constructor Question
Constructor Doubt