Forums Register Login

What is parent and child Class?

+Pie Number of slices to send: Send
Hi and Good Morning to all,

May I know what is the difference between the parent and the child classes.

I found out that the parent class is the base class and that the child class is derived from it and there is also the ancestor class and decendent, but I do not understand what it all means.

Is there any other way to explain this to make it easier to understand.

Is this concept the same for the Parent and Child Component?

Thank you

Rena Tjioe
+Pie Number of slices to send: Send
 

Originally posted by Rena Tjioe:

I found out that the parent class is the base class and that the child class is derived from it and there is also the ancestor class and decendent, but I do not understand what it all means.



Reusablity purpose

1.Inheritence is designed to support reusability.
2.To support the polymorphism
3.subclass can access superclass propeties vice versa not pssible.
[ it is like you can access your father properties,but your father can not access yours properties]

Hope this will help you
+Pie Number of slices to send: Send
Hi ,

Let me try,

A Child inherits some looks and behaviors from his parents.



A natural rule as I would say!

Similarly a child class inherits some behaviors from a parent class.But these behaviors are in the form of methods and some data.

Inheritance , Polymorphism , Encapsulation and Abstraction are the further principles of OOP's for Mapping the State(Data) and Behavior(method).
+Pie Number of slices to send: Send
 

Originally posted by seetharaman venkatasamy
3.subclass can access superclass propeties vice versa not pssible.
[ it is like you can access your father properties,but your father can not access yours properties]



Did you mean that using super class reference you cannot access child class specific members
Nothing stops from accessing the inherited members.


Hope this helps
+Pie Number of slices to send: Send
I know you will all complain I am being pedantic, but they are not called "child" and "parent." They are called "subclass" and "superclass."

"Parent" and "child" are used in Java for GUI components; if you have something inside something else, the "something" is called a "child" and the "something else" is called its "parent" and something outside that can be called an "ancestor."

Other languages might have different names, but that (as far as I can remember) is what they are called in Java.
+Pie Number of slices to send: Send
 

but they are not called "child" and "parent." They are called "subclass" and "superclass."


I agree Campbell, even from the OOP perspective, subclass and superclass make more sense than parent and child.
+Pie Number of slices to send: Send
 

Originally posted by Amit Ghorpade:

I agree Campbell, even from the OOP perspective, subclass and superclass make more sense than parent and child.

Maybe what they are called in C#, namely base class and derived class, is better, but "superclass" and "subclass" is what they are called in Java.
+Pie Number of slices to send: Send
Thanks Campbell
+Pie Number of slices to send: Send
You're welcome
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 13448 times.
Similar Threads
confuse in {Parent p = new Child();}
Very simple
generic erasure
Polymorphism - InstanceOf
confusing
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:08:16.