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 inheritance issue 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 "inheritance issue" Watch "inheritance issue" New topic
Author

inheritance issue

rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115
Hi,
I have a question that whenever I create the object of the derived class the constructor of superclass gets called.
I mean to say a constructor is called only when the object is created does that mean that whenever I create derievd class Object superclass Object also gets created.

Further I want to ask instance method is called only when object exists but I can call the superclass instance method
from the subclass method which I have overridden in subclass. without creating the superclass object.
How?

Thanks.

Rakesh Kadulkar
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

rakesh kankavlikar wrote:
I have a question that whenever I create the object of the derived class the constructor of superclass gets called.
I mean to say a constructor is called only when the object is created does that mean that whenever I create derievd class Object superclass Object also gets created.

Your Sub class Constructor calls "super()"[it calls your Super Classe's default Constructor] in his first line implicitly. please Avoid the term of "derived class " . it is not C++

rakesh kankavlikar wrote:
Further I want to ask instance method is called only when object exists but I can call the superclass instance method
from the subclass method which I have overridden in subclass. without creating the superclass object.
How?


that is what IS-A relationship is
 
 
subject: inheritance issue
 
Similar Threads
about super key
about static and instance initializer blocks with inheritance
Abstract class & constructor?
Servlet Concepts
default constructor