A class is a non-primitive
datatype that contains member variables (data) and member functions (methods)
that operates on the variables.  A class
is declared by the use of the class keyword. 
The general form of class definition is as follows.
            Syntax:            class class-name
                                    {
                                                datatype
instance-variable1;
                                                datatype
instance-variable2;
                                                -
                                                -
                                                datatype
instance-variablen;
                                                datatype
methodname1(parameter-list)
                                                {
                                                //
method body
                                                }
                                                -
                                                -
                                                datatype
methodnamem(parameter-list)
                                                {
                                                // method body
                                                }
                                    }
            The
data, or variables defined with in a class are called instance variables.  The code is present with in methods.  Collection of methods and variables defined
with in a class are called members of the class.
            Example:         class box
                                    {
                                    double width, height, depth;
                                    double
volume( )
                                    {
                                    return width*height*depth;
                                    }
                                    }
 
No comments:
Post a Comment