×

C++ Programs

C++ Most popular & Searched Programs

C++ Basic I/O Programs

C++ Constructor & Destructor Programs

C++ Manipulators Programs

C++ Inheritance Programs

C++ Operator Overloading Programs

C++ File Handling Programs

C++ Bit Manipulation Programs

C++ Classes & 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

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.