In C++, class is user defined data type, which is created using class keyword. Class is logical representation. In class, we can declare class members like variables, functions, constructor, destructor etc.
To access these class members we have to create object, which is physical representation of class. With the help of dot (.) operator, we access class members using object.
#include<iostream>
using namespace std;
class abc
{
public:
int x, y;
public:
int sum(int p, int q)
{
return (p+q);
}
};
int main()
{
abc ab;
ab.x=10;
ab.y=20;
cout<<ab.x+ab.y;
cout<<"\n";
cout<<ab.sum(30,50);
}
In the above example, we have created class with the name of abc. In this class we have declared class member variable x and y. we have also declared a method sum. In main function, we have created class abc object ab and access the class member variable and function.