What is the output of the following C++ program?
[gamipress_button type=”submit” label=”Run Code Online” onclick=”window.open(‘https://coderseditor.com’,’_blank’)”]
—-
#include <iostream> using namespace std; class A { public: void print() { cout << "A::print()"; } }; class B : private A { public: void print() { cout << "B::print()"; } }; class C : public B { public: void print() { A::print(); } }; int main() { C b; b.print(); }
Studently Answered question October 10, 2022
Output
Compiler Error: ‘A’ is not an accessible base of ‘C’
In the code above, there is multilevel inheritance. In “class B: private A,” take note of the access specifier. All members of “A” become private in “B” because the private access specifier is used. Class “C” is an inherited class from class “B.” An inherited class is unable to access private data members of the parent class, but print() of “C” tries to do so and returns an error as a result.
Studently Answered question October 10, 2022