โ Back to Inheritance
Question 125
Accessing Protected Members
Accessing Protected Members
A base class Person has been provided with a protected string name and a constructor that initializes it. A derived class Student publicly inherits from Person. The printName() function has been declared inside the Student class. Your task is to implement the printName() function outside the class. It should print the name member variable. Because name is protected (not private), it can be accessed directly in derived classes. Do NOT include a main function. Your code will be tested automatically. Expected output: Alice
Expected Output:
Alice
Topics:
Inheritance
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.