This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Constructers? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Constructers?" Watch "Constructers?" New topic
Author

Constructers?

santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Why Constructers are not inherited in subclass....? please explain with some good example


Creativity is nothing but Breaking Rules
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Nov 25, 2008
Posts: 66
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

Joined: Aug 03, 2008
Posts: 9293
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Constructers?