Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

constructor problem?

 
Vishy Karl
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Lakshmi Saradha
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Krishna Srinivasan
Ranch Hand
Posts: 1862
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class B doesn't define any constructors, it will call default no-argument constructor....
 
Vishy Karl
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OOps , Sorry for the silly mistake
Thanks for your replies
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic