• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritance - implicitly call superclass default constructor from subclass  RSS feed

 
henry leu
Greenhorn
Posts: 17
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a question in Java inheritance.

In subclass's constructor, if Java implicitly calls the superclass's default constructor, and what if there is no default superclass constructor exists? What does subclass call? Please advise.

Thanks!
 
Zachary Griggs
Ranch Hand
Posts: 83
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It causes a compiler error, saying there is no default constructor available. Try this code if you want to test:

 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch, Henry!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!