Home » Solved C++ programs » C++ Class and Object programs

C++ program to create a simple class and object

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;
 
class Hello
{
    public:
        void sayHello()
        {
                cout << "Hello World" << endl;
        }
};
 
int main()
{
    Hello h;
     
    h.sayHello();
     
    return 0;
}

Output

Hello World





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.