CLASS


                     PREVIOUS                                                                                                          NEXT

A class is a template definition of the methods and variables for a particular kind of object. In other words, class is the blue print from which an individual objects is created.A class definition starts with the keyword class followed by the class name; and the class body, enclosed by a pair of curly braces. A class definition must be followed either by a semicolon or a list of declarations.
Example :- we defined the Box data type using the keyword class as follows:

class Box 
{ 
   public: 
      double length;            // Length of a box 
      double breadth;           // Breadth of a box 
      double height;            // Height of a box  
}; 

The keyword public determines the access attributes of the members of the class that follow it. A public member can be accessed from outside the class anywhere within the scope of the class object. You can also specify the members of a class as private or protected.
Example :-Every human has eye, so eye color can be considered as the property of human being which can be encapsulated as a data in our class Human.

Class Human 
{   
    private: 
    EyeColor IColor; 
    NAME personname; 
}; 

Consider object of class of
Human myhuman;
we want set myhuman's name as "linto" and IColor as "black", For that we want methods to do that task. So need methods for class to do a particular task on the data.
Example :-

class Human 
{  
    private: 
    EyeColor IColor; 
    NAME personname; 
    public:  
void SetName(NAME anyName); void SetIColor(EyeColor eyecolor); };







Powered by Blog - Widget
Face Upward - Widget