0% found this document useful (0 votes)
17 views1 page

Inheritance

The document outlines a series of programming tasks related to inheritance in C++, categorized into basic, intermediate, and advanced levels. It includes creating classes, demonstrating various types of inheritance, method overriding, and polymorphism. Each task is designed to enhance understanding of object-oriented programming concepts in C++.

Uploaded by

chattaanply
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Inheritance

The document outlines a series of programming tasks related to inheritance in C++, categorized into basic, intermediate, and advanced levels. It includes creating classes, demonstrating various types of inheritance, method overriding, and polymorphism. Each task is designed to enhance understanding of object-oriented programming concepts in C++.

Uploaded by

chattaanply
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

� Basic Level

1. What is inheritance in C++? Explain with an example.


2. Create a class Animal with a method sound(). Inherit this class in Dog and override the sound() method.
3. Write a program to demonstrate single inheritance using classes Person and Student.
4. Define a base class Vehicle with fields brand and a method start(). Inherit it in Car and Bike.
5. Create a class Shape and extend it in Circle and Rectangle. Add a method to calculate area in each.

� Intermediate Level

6. Create a multilevel inheritance example with LivingThing → Animal → Dog. Each class should have one method.
7. Demonstrate hierarchical inheritance with a base class Employee and derived classes Manager, Developer.
8. Create a class Account with method displayBalance(). Inherit it in SavingAccount and CurrentAccount, overriding
the method.
9. Create a class Bank with a constructor. Inherit it in class Branch. Call the superclass constructor using super().
10. Show method overriding and use of super.methodName() in the child class.

� Advanced Level

11. Create a class hierarchy to represent:

 Employee (name, id)


 PermanentEmployee (salary)
 ContractEmployee (hourlyRate, hoursWorked)
 Write a method calculateSalary() in each.

12. Use the final keyword in a method and try to override it in a subclass. Observe the result.
13. Demonstrate upcasting and downcasting with a superclass and subclass.
14. Create a class A with a method show(). Create B extends A, override show(), and access it via parent and child class
references.
15. Write a program where:
o Parent class Shape has a method draw().
o Subclass Circle, Square, and Triangle override draw().
o Use polymorphism to call correct draw() method for an array of shapes.

You might also like