This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes constructor problem? 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 problem?" Watch "constructor problem?" New topic

constructor problem?

Vishy Karl
Ranch Hand

Joined: Sep 08, 2003
Posts: 116
Hi All ,
Why does the foll. code compile??

I was expecting a compile time error as teh Class B does not contain the no-arg. constructor . Then how is the call to super(); in Class C resolved ???
Thanks in advance,
Best wishes,

"The man who can drive himself further once the effort gets painful is the man who will win." <br />Roger Bannister
Lakshmi Saradha
Ranch Hand

Joined: Oct 21, 2003
Posts: 170
Hi Vishy,
This is a tricky question.The line
public boolean B(String msg)
is a method and not a constructor since there is a boolean return type.
Sice there is no constructor,, a default nor arg constructor is provided adn hence this code gives no compiler error.

Thanks,<br />Lakshmi.
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1849

class B doesn't define any constructors, it will call default no-argument constructor....

Krishna Srinivasan
OCAJP 7/8 Exam, 400+ OCPJP Mock Questions
Vishy Karl
Ranch Hand

Joined: Sep 08, 2003
Posts: 116
OOps , Sorry for the silly mistake
Thanks for your replies
It is sorta covered in the JavaRanch Style Guide.
subject: constructor problem?
jQuery in Action, 3rd edition