+2 votes
in Class 12 by kratos

A class One with data members int a and char b inherits from another class Two with data members float f and int x. Write definitions for One and Two for the following situations:

(i) Objects of both the classes are able to access all the data members of both the classes.

(ii) Only the members of class One can access all the data members of both the classes.

1 Answer

+2 votes
by kratos
 
Best answer

(i) class Two

{

protected:

float f;

int x;

};

class One:private Two

{

int a;

char b;

};

(ii) class Two

{

public:

float f;

int x;

};

class One:public Two

{

public:

int a;

char b;

};

...