Wednesday, 4 January 2012

Classes and Objects


Classes and Objects:

-          A class is an user defined datatype which consists of methods and memberVariables.
-          An object consists of the data and the code that acts up on the data.
Ex:
                Class Emp  {
                                int empno;                                          //member variable
                                String ename;                                    //member variable
                                float salary;                                         //member variable
                               
                                public String getEname() {             //method
                                                return ename;
                                }
                               
}

To access methods or memberVariables we need instances, like
                Emp emp1 = new Emp();
                emp1.getEname();


-          In simple language,
Class is a blueprint of an Object, Object is an instance of a class.
-          In OOPs, the fundamental data storage is an Object. i.e..



-          Hence,
A class is a conceptual part of a program ,
An object is the physical representation of a class.
-          Any object must possess the following characteristics:

o    State
§  It represents the data.
§  It is indicated by attributes , values for these attributes.
o    Behavior
§  It represents the methods.
§  It refers to the change of the state over a period of time.
o    Identity
§  It represents the name of the object.
§  Each object must have an unique identity.

No comments:

Post a Comment