Home »
C++ programs »
C++ class and object programs
C++ program to create a simple class and object
Learn, how can we create a simple class and its object in C++ program?
[Last updated : March 01, 2023]
Creating a simple class and object in C++
In this program you will learn how to create a class, create object of that class and calling the member function in main function.
Simple class and object creating program in C++
// C++ program to create a simple class and object
#include <iostream>
using namespace std;
// Creating a class named "Hello"
class Hello {
public:
void sayHello()
{
cout << "Hello World" << endl;
}
};
// The main function
int main()
{
// Creating an object of "Hello" class
Hello h;
// Callng the member function
h.sayHello();
return 0;
}
Output
Hello World