Chapter 15: Problem 5
Can a derived class ever directly access the private members of its base class?
/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none}
Learning Materials
Features
Discover
Chapter 15: Problem 5
Can a derived class ever directly access the private members of its base class?
All the tools & learning materials you need for study success - in one app.
Get started for free
A program uses two classes: Dog and poodle. Which class is the base class and which is the derived class?
A(n) ________ class cannot be instantiated.
Protected members of a base class are like ________ members, except they may be accessed by derived classes.
What is the class access specification of the base class named below? class Pet : public Dog
Write the declaration for class \(B\). The class's members should be \(\bullet\) \(\mathrm{m},\) an integer. This variable should not be accessible to code outside the class or to member functions in any class derived from class B. \(\bullet\) \(\mathrm{n},\) an integer. This variable should not be accessible to code outside the class, but should be accessible to member functions in any class derived from class B. \(\bullet\) setM, getM, setN, and getN. These are the set and get functions for the member variables m and n. These functions should be accessible to code outside the class. \(\bullet\) calc, a public virtual member function that returns the value of m times n. Next write the declaration for class \(\mathrm{D}\), which is derived from class \(\mathrm{B}\). The class's members should be \(\bullet\) \(\mathrm{q},\) a float. This variable should not be accessible to code outside the class but should be accessible to member functions in any class derived from class \(\mathrm{D}\) \(\bullet\) \(\mathrm{r},\) a float. This variable should not be accessible to code outside the class, but should be accessible to member functions in any class derived from class D. \(\bullet\) setQ, getQ, setR, and getR. These are the set and get functions for the member variables \(q\) and \(r .\) These functions should be accessible to code outside the class. \(\bullet\) calc, a public member function that overrides the base class calc function. This function should return the value of q times \(r\)
What do you think about this solution?
We value your feedback to improve our textbook solutions.