Friday, February 18, 2011

Classes and objects and Methods and properties



**************Classes and objects and Methods and properties**********
 
A class is a user defined data type like a structure or a union. 
A class consists of data variables and functions. 
These variables and functions are called members of the class. 
The variables are called data members and functions are called member functions. 
The member functions are also called methods. 
The data members are called properties of the class. 
An object is the instance of the class. 
An object is like a compound variable of the user defined type.
It links both code and data. Within the object, members of the class can be public or private to the object. 
The declaration of a class is syntactically same as structure. The class is declared using keyword class.
The general form of the declaration of the class is:-

class class_name
{
          

            access_specifier:

                        data members

            access_specifier:

                        data functions

 

} object_list;

*****Why Use a Class****
Once a class has been created the programmer can:
1) create multiple instances of a class 
2) reuse classes in more than one program

****Access Specifiers***
1) Private members of a class are accessible only from within other members of the same class or from their friends. 
2) Protected members are accessible from members of their same class and from their friends, but also from members of their derived classes. 
3

No comments:

Post a Comment