What is Function or Data Method?
In C language we have a function, so data method are nothing new they are also function but in many programming language like C++, java etc function are called as data method.
-function inside class called as data method
How make function or data method inside class?
program:
#include < iostream>
using namespace std;
//Create class
class myclass
{
public:
//Create data method(function)
int func(int value)
{
cout<<"This is my function"<< endl;
cout<<"And value is: "<< value;
}
};
int main()
{
//create object
myclass obj;
//call data method and pass value as 10
obj.func(10);
return 0;
}
This is my function
And value is: 10