C++ - Class and Object With Syntax

C++ - Class A class is a collection of objects of similar type which have same property and common behavior. For example, roll, name, age, are the member of class student and pigeon, sparrow, crow, etc are the object of the class bird.

C++ - Class

A class is a collection of objects of similar type which have same property and common behavior. For example, roll, name, age, are the member of class student and pigeon, sparrow, crow, etc are the object of the class bird.

A class is a user defined data type which holds both data and functions. The internal data of class is called data member and functions are called member functions. The member functions mostly manipulate the internal data of a class.

C++ Code

class class_name{
private:
        variable declaration;
        function declaration;
public:
        variable declaration;
        function declaration;
};
eg. 
class student{
         int roll;
         char name[20];
         int age;
     public;
           void getdata();
           void displaydata();
}

C++ - Object

The object is the combination of data and functions in a single unit. The object can interact without having to know details of each other's data or code.

It is sufficient to know the type of message accepted and the type of response returned by the objects. Example, automobiles are an object as they have size, weight, color etc. as attributes data, and starting,turning the wheel, processing, accelerator pedal etc. as operation.

C++ Syntax

object: employee
data 
     sn
     name 
     age
     dob
     ...
     ...
functions
     netsalary
     providentfund

You May Also Like...

Socialize with Us