This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Constructers?  RSS feed

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why Constructers are not inherited in subclass....? please explain with some good example
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
santhosh.R gowda wrote:Why Constructers are not inherited in subclass....?


i dont know whether my answare satisfy you or not. Coming to your question, you can access super class constructor from subclass constructor only by using super(). more over Constructor must have same name as Class name. so you cant override(inherit) constructor unlike method
 
Birla Murugesan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman venkatasamy wrote:
you can access super class constructor from subclass constructor only by using super(). more over Constructor must have same name as Class name. so you cant override(inherit) constructor unlike method


obviously,this is right one

And also ,constructor of super class cann't be inherited by their sub class unlike super class methods.
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the use of a constructor getting inherited. You cannot explicitly call a constructor of a class on a reference of that class. Constructors are only called using new operator. So if a constructor is inherited, it will serve no purpose at all as you can't call it on an object of the sub-class...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!