File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 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 "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: 38441
    
  23
Originally posted by shruti patel:
Can we inherit the constructor in a Class?
No
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41592
    
  55
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.


Ping & DNS - my free Android networking tools app
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: 9293
    
  17

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inhertance