
Classes, Objects, and Memory 277
cout<<“ p = ”<<p <<“ h = ”<<h <<“ m = ”<<m;
}
protected :
int m;
void getm()
{
cout<<“ In mget() enter value of m : ”;
cin>>m;
}
};
int main()
{
clrscr();
access a; // object declaration
// a.p=2; // access to private member is not possible.
// a.pget() // -----------” -----------------
// a.m=5; // access to protectd member is not possible
// a.mget(); // ----------------” ---------------------
a.h=4; // direct access to public member is possible
a.geth();
return 0;
}
OUTPUT
In geth():
In pget() enter value of p:7
In mget() enter value of m: 4
p = 7 h = 4 m = 4
Explanation: In the above program, the class ...