Which among the following is true for the given code below? [code] class A { protected : int marks; public : A() { marks=100; } disp(

Thanh Thảo

New member
Which among the following is true for the given code below?
Code:
class A
{
	protected : int marks;
	public : 
	A()
	{ 
		marks=100; 
	}
	disp()
	{ 
		cout<<”marks=”<<marks; 
	}
};
class B: protected A
{
};
B b;
b.disp();
A. Object b can’t access disp() function
B. Object b can access disp() function inside its body
C. Object b can’t access members of class A
D. Program runs fine
 
Answer: a
Explanation: The object of class B can’t access the members of A outside the class. This is because the class is being inherited in protected access, so all the members will become protected in subclass B.
 

Tìm kiếm

Back
Top