Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What happens to parent class object when a child class's object is created?

 
Sumeet H Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I had a doubt regarding creation of object in relation to inheritence.
Whenever you instantiate a Child class object, the parent class's contructor is also called. In other words, in addition to creating the child's object we are also creating the parent's object(let me know if there is a fallacy in this assumption).

My question is that since we actually use only the child class's object, what happens to the parent class's object(is it garbage collected??), and why is it created in the first place?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's only one object created. (which should answer your questions )
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A side note: You should not use the words "parent class" and "child class".

The words "parent" and "child" are not commonly used when talking about inheritance in the object oriented programming sense. Note that the biological meaning of the word "inheritance" is very different from the meaning of the term "inheritance" in OO programming.

In OO programming, "inheritance" indicates an is a relationship: if class Dog extends Animal, then an instance of Dog is an instance of Animal. Note how this would sound wrong if I would have class Child extends Parent: a Child is a Parent?

So, don't use those terms: say "superclass" instead of "parent class" and "subclass" instead of "child class".
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper Young wrote:A side note: You should not use the words "parent class" and "child class".

I think this is a bit subjective. The Java tutorial also uses the parent/child wording and I think it is widely used :
Definitions:
A class that is derived from another class is called a subclass (also a derived class, extended class, or child class). The class from which the subclass is derived is called a superclass (also a base class or a parent class).
 
Sumeet H Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Christophe for the answer
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:
Jesper Young wrote:A side note: You should not use the words "parent class" and "child class".

I think this is a bit subjective.

In my opinion, confusing the biological meaning of the word "inheritance" with its meaning in OO programming makes it harder for people to understand what "inheritance" means in OO programming.

When you're talking about a "parent class" and "child class", it's harder to understand that there's an is a relationship between those two (which is the essential point in understanding inheritance in OO programming). That's why I want to discourage people to use words that refer to the biological meaning of the word.
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
give me the answer
 
Rob Spoor
Sheriff
Pie
Posts: 20510
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a bit rude, isn't it? Demanding the answer to someone else's question while Christophe already answered it in the first reply.
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper Young wrote:That's why I want to discourage people to use words that refer to the biological meaning of the word.

Thank you Jesper. I understand why you want to discourage the use of these words
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chetan Dorle,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic