Monday 25 July 2011

What is a Class,Object and Inheritance.

Class:- The Image of  an object is class class. When you create a class you create a you own DATA Type.
ForExample:- if  I write int x it means, variable x will have an integer type. When you create Human Class  then I can write  Human  h;  It mean  h is a variable which can have the data of Human type.


Objects:- Any thing which will have properties and functions. The  Human Object, of class Human will have the properties like age,name,color; and function will setAge(), setName(), getAge(), getName();


Inheritance:- Is explained as two type of relationships 1)IS A relation ship 2) Has a relationship. For example the java class  as follow explains is a  relationship;
that is:-; Class Student extends Human{ } 
you can read it as  Student is a Human. This concept is class association.


On the other hand,

if you write  Class Student {

 Human h=new Human();      //This is called aggregation concept. That is the has a relationship which
                                            //mean Student class has a  Human class object. 
}

No comments:

Post a Comment