aspose file tools
The moose likes Beginning Java and the fly likes Inhertance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inhertance" Watch "Inhertance" New topic
Author

Inhertance

shruti patel
Ranch Hand

Joined: Mar 10, 2008
Posts: 52
Can we inherit the constructor in a Class?please give one
example.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 41616
    
  31
Originally posted by shruti patel:
Can we inherit the constructor in a Class?
No
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42954
    
  73
How would you test whether constructors are inherited? Tell us what code you'd need to do so. Once you have the code, you can compile and run it, to see what happens.
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
By default constructors are not inherited. You can call a superclass constructor in an inheritance chain by using the "super." keyword.


be a well encapsulated person, don't expose your privates, unless you public void getWife()!
cheng jian
Greenhorn

Joined: Jul 28, 2008
Posts: 7
Originally posted by shruti patel:
Can we inherit the constructor in a Class?please give one
example.

For constructor we can do one thing.
Overloading!!
A example from SCJP

The inhertance is used for a class.
(Sorry i'm poor about english!)
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9327
    
  19

constructors are not inherited

here's the code to support this



this is ConstructorTry class in A package

There is another class ConstructorTry in package B



the line marked will give an error that there is no constructor in Constructor try that takes a String. If the constructor of A.ConstructorTry was inherited then the line would have compiled as A.ConstructorTry has a constructor which takes a String and B.ConstructorTry is a sub-class of A.ConstructorTry.

Hope this is OK.......


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
Have you tried LearnNowOnline? http://www.learnnowonline.com/
 
subject: Inhertance