Recent

recentposts

Basic of Class

 Basic of Class

A class is a group of elements  that share common properties and relationships.

Syntax:

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.

class

class

class


SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

Please give your valuable suggestions