Lesson 17 of 24

InheritanceInheritance

10 min 35 XP

class Car : public Vehicle என்றால் Car, Vehicle-ன் public மற்றும் protected உறுப்புகளைப் பெறும். Derived constructor, base constructor-ஐ initializer list-ல் அழைக்கும். C++ multiple inheritance-ஐயும் ஆதரிக்கிறது.

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

Employee base class: name, salary; double pay() salary-ஐத் தரும். Manager : public Employee, கூடுதல் bonus; payWithBonus() salary + bonus. main()-ல் name, salary, bonus படித்து print செய்யுங்கள்: Input: Ravi 50000 7500 Output: Ravi base pay: 50000 Ravi total pay: 57500

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.