Home >>Cpp Programs >Create a class method in C++
In this example, we will see a C++ program to crate class methods and also access the class methods outside of the class.
Program:
#include <iostream>
using namespace std;
// class definition
// "Sample" is a class
class Sample {
public: // Access specifier
// method definition 1
void printA()
{
cout << "Abhimanyu\n";
}
// method definition 2
void printB()
{
cout << "Jerry\n";
}
// method definition 3
// it will accept value while calling and print it
void printValue(int value)
{
cout << "value is: " << value << "\n";
}
};
int main()
{
// creating object
Sample obj;
// calling methods
obj.printA();
obj.printB();
obj.printValue(007);
return 0;
}