Computer Science, asked by Praisy162003, 10 months ago

Please answer the 4th question

Attachments:

Answers

Answered by poojan
1

Answer:

(C) Protected

Explanation:

Let me clarify it to you over here.

class base  

{

public:

 int x;

protected:

 int y;

private:

 int z;

};

class Derived: base

{

// x is public

// y is protected

// z is not accessible from base

};

class unknown: Derived

{

// x is public

// y is not accessible from derived

// z is not accessible from derived

}

In this case, we can access both x (public) and y (protected) can be accessible in Derived class as it is inherited from class base; it's parent.

But, in case of class unknown, only x is accessible from base as it is in public mode, where b and c can't be accessible as neither class unknown can access inherited protected members protected members, nor it can access any class's private variables.

So, in order to access features of base class to derived class but not to the class derived from derived class, we use protected mode.

Similar questions