31.3k views
0 votes
Consider the following base and derived class declarations: class BaseClass { public: void BaseAlpha(); private: void BaseBeta(); float baseField; }; class DerivedClass : public BaseClass { public: void DerivedAlpha(); void DerivedBeta(); private: int derivedField; }; For each class, do the following:

a) List all private data members.
b) List all private data members that the class's member functions can reference directly.
c) List all functions that the class's member functions can invoke.
d) List all member functions that a client of the class may invoke.

User Woolstar
by
3.3k points

1 Answer

4 votes

Answer:

a) Baseclass - baseField

DerivedClass - derivedField

b) BaseClass - baseField

DerivedClass - derivedField

c) BaseClass - BaseBeta(), BaseAlpha()

DerivedClass - BaseAlpha(), DerivedAlpha(), DerivedBeta()

d) BaseClass - BaseAlpha()

DerivedClass - BaseAlpha(), DerivedAlpha(), DerivedBeta()

Step-by-step explanation:

a) Since, private members of a class cannot be inherited, that is why, DerivedClass has only one private data member.

b) Member function of a class can invoke private data variables of the class, so, they can refer to their private members on their own but DerivedClass has no access to BaseClass's private members.

c) Every member function of a class can invoke every other member function of that class, but DerivedClass's member function cannot invoke BaseClass's private member functions.

d) Object of a class has no access to private members of a class, that is why they can invoke only public member functions of the class.

User Azpiri
by
3.4k points