File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Constructors" Watch "Constructors" New topic


awad saleh

Joined: Jul 04, 2007
Posts: 22
Can a constructor of a super class be inherited.? Wat does this line means? when we inherit a super class, is the super class constructed not inherited? Explain me with code snippet.
saurav sarkar
Ranch Hand

Joined: Jan 07, 2007
Posts: 180

In a sub class if you dont provide a constructor.......then it will
automatically call the no argumented constructor of the super class.

If the constructor is provided in the sub class, then through the super keyword the constructors of the super class can be inherited for both
argumented and non-agrumented.
whether implicit or explicit call of construtors 'constructor chaining
happens to the object class's constrtuctors.

Experts please correct me if i am wrong.

Be Objectively Oriented.Explore the power of OOPs.
My Blog, Eclipse EMF Query committer.
Maurizio Nagni
Ranch Hand

Joined: May 29, 2004
Posts: 75
inerit a constructor is not s proper definition. Your class inerit from its parent anyway you can say that the constructors of your your class can instantiate one of the constructors of its parent; which one is your choose.

If you have something like

when you intantiate

when you intantiate or

it automatically call the default constructor of the animal class Animal.

But if you instantiate

it will call the constructor of Animal which take a String as parameter.

This process can be replicated if you another class extends the Mammal class; take the example below

the constructor Dog(String name) will instantiate (in order) the following contructors
1) Animal()
2) Mammal(int numLegs)
3) Dog(String name)

on the other side the Dog() will instantiate
1) Animal(String name)
2) Mammal(String name)
3) Dog()

I agree. Here's the link:
subject: Constructors
jQuery in Action, 3rd edition