This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes constructors are not inherited? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "constructors are not inherited?" Watch "constructors are not inherited?" New topic
Author

constructors are not inherited?

hari harann
Ranch Hand

Joined: Aug 07, 2008
Posts: 54
i have read that constructors are not inherited... although i have referred so many for this i could not get the point right. if constructors are used for declaring and initialising the variables, then will there be any use inheriting the class without constructors.???
please hint me on this...
Ronald Schild
Ranch Hand

Joined: Jun 09, 2008
Posts: 117
Somehow a constructor of a class that you inherit from is called at a certain point that has to do with construction.

Vague hint is vague?


Java hobbyist.
hari harann
Ranch Hand

Joined: Aug 07, 2008
Posts: 54
oops.. Ronald i should have told like 'please explain me'
Ronald Schild
Ranch Hand

Joined: Jun 09, 2008
Posts: 117
No I didn't mean that you're vague, you asked for a hint and I gave one that I thought was vague. I guess it was.


If you inherit a class, if you do not explicitly call the constructor of the super class in the sub class constructor, the compiler does this for you.

Up to you to find out what this means, and what the compiler does.
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Iif you wish to explicitly use the supercalss constructor you must make a call to super. in your subclass, if not your subclass will either get a default constructor or you will have to create a non-default construcor.


be a well encapsulated person, don't expose your privates, unless you public void getWife()!
Juan Manuel Alberto de los Santos
Ranch Hand

Joined: Jun 26, 2008
Posts: 48
What do you think that will happen if you try to compile this ...



if you don't know the answer, just read about "default constructors"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: constructors are not inherited?
 
Similar Threads
doubt
Constructors are not inhertied - True
Constructors!
Why I can't call the parent class constructor?
another question on constructors