Creating Variables and Accessing them in Methods in a Class
This video tutorial explains how to create properties or the variables in a class and how to access it from the methods of that class.
You will learn what are the access specifiers, how to create a variable, how to access the variable from the methods, how to initialize the variables in detail with example.
source code for this tutorial
#include <iostream>
#include <string>
using namespace std;
class HumanBeing{
public:
string name;
void introduce(){
cout << "hi i am "<<name<<endl;;
}
};
int main()
{
HumanBeing anil;
anil.name = "anil";
anil.introduce();
HumanBeing anjali;
anjali.name = "anjali";
anjali.introduce();
return 0;
}