*
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
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: 9291
    
  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
 
Consider Paul's rocket mass heater.
 
subject: Constructers?
 
Similar Threads
Constructers
ambiguous constructers