Class & Object in C++

Class:  A class is a user defined data type which contains the data members and member function.

A class forms the basis for object oriented programming.

 It describes the shape and nature of the object .

Any concept that we want to implement in oop’s must be encapsulated in class.

The internal data of the class are called data members and functions are called member functions.

The variable of the class are called object or instance of the class.

A class is a template for an object and an object is an instance for a class.

Syntax for declaring a class:

Example

In the above example we have created a new class “student”.

Inside the student class we have created two private data member age & name[20] and two public member function input() & show().

Object: we can access data members and member function outside of the class by using the object.

Object is a run time entity. 

Syntax for object creation:

Class_name   object_name;

Example:    student   obj;    

Note:    Here student is a name of the class and “obj” is a name of the object.

Note: we can create more than one object of the class. Foe example:

Note: By using the object and (.) dot operator  you can access public data member of the calss.

Categories C++