File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes What is parent and child Class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is parent and child Class?" Watch "What is parent and child Class?" New topic
Author

What is parent and child Class?

Rena Tjioe
Greenhorn

Joined: Jul 01, 2008
Posts: 3
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
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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
Rakesh Chaudhary
Ranch Hand

Joined: Feb 19, 2008
Posts: 120
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).
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2718
    
    6

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


SCJP, SCWCD.
|Asking Good Questions|
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40059
    
  28
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.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2718
    
    6

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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40059
    
  28
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.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Thanks Campbell
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40059
    
  28
You're welcome
 
 
subject: What is parent and child Class?