File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Constructor Question

David Kennedy
Ranch Hand

Joined: Jan 22, 2006
Posts: 33

Im just wondering why doesnt this compile


"There are only 10 types of people in the world: Those who understand binary, and those who don't"
Max Vandenburg
Ranch Hand

Joined: Mar 09, 2006
Posts: 51
its because the constructor in the Top class takes an argument string....

for it to work, either explicitly add super("someString"); to your Bottom2() constructor i.e.

or create an constructor in the Top class that takes no arguments.

marc weber

Joined: Aug 31, 2004
Posts: 11343

Like Firman said. Remember...
  • If there is no explicit call to this(...) or super(...), the first line of a constructor is an implicit call to super() with no arguments.
  • A default no-args constructor will be automatically provided by the compiler only if no other constructor is provided by the programmer.
  • In this case, a Top constructor accepting a String is provided by the programmer, so the compiler does not provide a no-args constructor for Top. The constructor for the subclass, Bottom2, does not call super explicitly, and so super() with no arguments is implicitly called. This is a problem, because there is no such constructor.

    "We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
    David Kennedy
    Ranch Hand

    Joined: Jan 22, 2006
    Posts: 33
    I understand it now.

    Thanks for the help

    I agree. Here's the link:
    subject: Constructor Question
    It's not a secret anymore!