- A class is a blueprint that doesn't exists and works as template for objects.
- A class contains member data or member functions together.
- Generally class contains two concept :
- Class declaration
- Definition of functions
- A class uses keyword “class” before the class name and semicolon is used for terminating the declaration of class.
};Access modifiers :
- Access modifiers provides security to the data members and member function of the class.
- It doesn’t allow them to move around.
- It decisides the visibility of data.
- Three keywords are used:
- private : it is default access modifier. And these data members are accessible within a class in which it is declared.
- public: it is accessible at anywhere in program.
- protected: it is accessible within a class in which it is declared or accessible in immediate derived class.
//example of a class member function declared inside it
int result( )
//example of class declaration and member functions are declared outside class using scope resolution
int num1, num2;
int result( );
void display( );
int sum::result( )
void sum ::display( )
cout<<”two numbers are = “<
Creating an objects :
- The declared willn’t work until its object is not created.
- A class works as blueprint or template for objects.
- A class decides the behavior of an object.
- More than one object of a same class can be created.and must be declared in main( ).
- Syntax :
to access member functions of class dot operator is used.
A class is declared before and after that creation of object
}A simple C++ program with class :
void input( )
cout<<”enter principal, time , rate for calculation”;
void calculation( )
cout<<”simple interest is= “<
void main( )