CJCoding With Joseph
15per day

Inheriting and Extending a Constructor

You are given a base class Person with protected members name (string) and age (int), plus a constructor and a virtual display() function.

Create a derived class Student that:
- Publicly inherits from Person
- Has a private string member: major
- Has a constructor that takes name, age, and major (call the base constructor for name and age)
- Overrides display() to print all three fields on separate lines:
  Name: [name]
  Age: [age]
  Major: [major]

Do NOT include a main function. Your code will be tested automatically.

Expected output:
Name: Alice
Age: 20
Major: Computer Science

Expected Output:

Name: Alice
Age: 20
Major: Computer Science
Topics:
ClassesInheritance
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.