Ask Question

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.

+4
Answers (1)
  1. 29 November, 20:58
    0
    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 ()

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Consider the following base and derived class declarations: class BaseClass { public: void BaseAlpha (); private: void BaseBeta (); float ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers