• Post Reply Bookmark Topic Watch Topic
  • New Topic

Constructers?  RSS feed

 
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
 
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
 
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.
 
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...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!