In a inheritance, the members of the base class are members of the 21. public public private derived class. They can be accessed by the member functions (and functions) of the friend derived class. The members of the base class are members of the derived protected private class. They can be accessed by the member functions (and functions) of the derived friend class. The members of the base class are hidden in the derived class. They cannot be private directly accessed in the derived class. They can be accessed by the member functions (and functions) of the derived class through the or members of the friend public protected derived class. The members of a base class can be directly accessed by the member functions of 23. protected the derived class, but they cannot be directly accessed in a program that uses that class. The members of a class can be directly accessed by the member functions of any derived public class as well as in a program that uses that class. The members and are members in The 25. setX, y, setY protected class third. member of is hidden in and it can be accessed in private x class first class third class only through the and members of third protected public class first. Because the is not specified, it is a private inheritance. Therefore, 27. memberAccessSpecifier all the members of the becomes members in class first private class second. a. 29. void two::setData(int a, int b, int c) { one::setData(a, b); z = c; } b. void two::print() const { one::print(); cout << z << endl; }
21. In a public inheritance, the public members of the base class are private members of the derived class. They can be accessed by the member functions (and friend functions) of the derived class. The protected members of the base class are private members of the derived class. They can be accessed by the member functions (and friend functions) of the derived class. The private members of the base class are hidden in the derived class. They cannot be directly accessed in the derived class. They can be accessed by the member functions (and friend functions) of the derived class through the public or protected members of the derived class. 23. The protected members of a base class can be directly accessed by the member functions of the derived class, but they cannot be directly accessed in a program that uses that class. The public members of a class can be directly accessed by the member functions of any derived class as well as in a program that uses that class. 25. The members setX, y, and setY are protected members in class third. The private member x of class first is hidden in class third and it can be accessed in class third only through the protected and public members of class first. 27. Because the memberAccessSpecifier is not specified, it is a private inheritance. Therefore, all the members of the class first becomes private members in class second. 29. a. void two::setData(int a, int b, int c) { one::setData(a, b); z = c; } b. void two::print() const { one::print(); cout << z << endl; }
Odd%20Numbered%20Exercises%20Solutions.docx