class and object in C++

What are class and object in C++?


A class is a user-defined data type that has data members and member functions. Data members are the data variables and member functions are the functions that are used to perform operations on these variables.

An object is an instance of a class. Since a class is a user-defined data type so an object can also be called a variable of that data type.

A class is defined as-

class A{
private:
 int data;
public:
 void fun(){

 }
};
Class and Object in C++

For example, the following is a class car that can have properties like name, color, etc. and they can have methods like speed().

Comments