Lesson 17 of 24

Inheritance

10 min 35 XP

class Car : public Vehicle gives Car the public and protected members of Vehicle. The derived constructor calls the base constructor in its initializer list. C++ even supports multiple inheritance.

Example: edit me and press Run

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.

Challenge

+35 XP

Write base class Employee (name, salary, double pay() returning salary) and Manager : public Employee with an extra bonus and payWithBonus() returning salary + bonus. In main(), read name, salary and bonus and print: Input: Ravi 50000 7500 Output: Ravi base pay: 50000 Ravi total pay: 57500

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.