Home >>Cpp Programs >C++ Classes and Objects Program
In this example, we will see a C++ program in which we will create an object of a class and access class attributes.
Program:
#include <iostream>
#include <string>
using namespace std;
// class definition
class Hello {
public: // Access specifier
int ID;
string Name;
string Place;
};
int main()
{
// object creation
Hello a;
// Accessing attributes and setting the values
a.ID = 101;
a.Name = "Jerry";
a.Place = "Noida";
// Printing the values
cout << "ID: " << a.ID << "\n";
cout << "Name: " << a.Name << "\n";
cout << "Place: " << a.Place << "\n";
return 0;
}