Consider the class hierarchy shown below.
class A
{ int a;
protected:
int b;
public:
int c; };
class B: protected A
{ };
Class C: public B
{ };
Which data members of class A are accessible
- in class B
-in class C
-in main function
Justify your answer.
Members of class A accessible in class B are b and c this is because B inherits protected members of A while c is public.
Members of class A accessible in class C is c because c is public and is accessed from anywhere.
In main function c is accessible since it is public and can be accessed from anywhere.
Comments
Leave a comment