C++ Classes and Objects

Definition of Class

Class is an user defined data type, which holds its own data members and member functions, which can be accessed and used by creating instance of that class. The variables inside class definition are called as data members and the functions are called member functions.


Class name must start with an uppercase letter(Although this is not mandatory).

Classes contain, data members and member functions, and the access of these data members and variable depends on the access specifiers

A class is used to specify the form of an object and it combines data representation and methods for manipulating that data into one neat package. The data and functions within a class are called members of the class.!


Definition of an Object

An Object is an instance of a Class. When a class is defined, no memory is allocated but when it is instantiated (i.e. an object is created) memory is allocated.

A class is defined in C++ using keyword class followed by the name of class. The body of class is defined inside the curly brackets and terminated by a semicolon at the end.


Example 1:


Example 2:



Example 3:



Output :

    Codername is: Prayag