A class is a structured data type in C++ which is a collection of variables and functions. A class in C++ combines related data and functions together. It makes a data type which is used for creating objects of this type.
The syntax of a class definition:
Where
- Class is a keyword in C++
- name_of_the_class is the name of the class and can be treated as the user defined data type.
- The pair of flower braces indicates the body of the class
- The semicolon (;) after the right brace is must.
- The variables are declared inside and are called data members.
- The member functions can access or manipulate data members without passing them as parameters.
- The private,protected and public are access specifiers for the members of class.
-
Syntax of object declaration:
classname objectname1, objectname2, …..,
Example;
In the above example, student is a class haveing regno, fees and name as data members. The getdata() and printdata() are the members functions of the class. The obj1 and obj2 are objects of class student.