What is class in programming ?
In programming, a class is a blueprint or a template that defines the structure and behavior of objects.
It serves as a reusable programming construct that encapsulates data (member variables) and functions (member functions).
Syntax for defining a class in C++:
C++
class ClassName {
// Member variables
// Member functions
};
What is an object in programming ?
In programming, an object is an instance of a class.
Syntax to creates a class object:
C++
ClassName objectName;
Program to show use of Class and Object in C++:
C++
#include <iostream>
class Papa { // create class Papa
public:
int age=30; // member variable
void show() //member function
{
cout <<age;
}
};
void main() {
Papa obj; // create object obj
obj.show();
}
C++ Output
30