Basic of Class
class class_name{
private:
variable declaration ;
function declaration( ) ;
protected:
variable declaration ;
function declaration( ) ;
public:
variable declaration ;
function declaration( ) ;
} ;
Example:
class mydata{
private:
int a, b ;
protected:
int c ;
public:
int d
;
void toEnterData( int a1, int b1, int c1 ) {
a = a1 ;
b = b1 ;
c = c1 ;
}
void toDisplayData( ) {
cout<<”\n The value of a =
”<<a<<endl ;
cout<<”\n The value of b =
”<<b<<endl ;
cout<<”\n The value of c = ”<<c<<endl ;
cout<<”\n The value of d =
”<<d ;
}
} ;
Private Members are
the members of class which can be accessed only from within the class. They
cannot be used or accessed directly outside the class.
Protected Members are
the members of class which can be accessed only from within the class but can
be used in another class through inheritance. They cannot be used or accessed
directly outside the class.
Public Members are
the members of class which can be accessed within the class, can be used in
another class through inheritance and can be used or accessed directly outside
the class.
Data Variable are
the data-type properties that describes the characteristic of a class. There
may be zero, one or more than one data variable.
Like a, b, c (
from above example ).
Member Functions/class method are the set of operations that may be applied to objects of that class. There may be zero, one or more than one member function.
0 comments:
Post a Comment
Please give your valuable suggestions