0% found this document useful (0 votes)
25 views4 pages

Practice Sheet

The document contains a practice sheet with various inheritance questions in programming, covering single, multilevel, multiple, hierarchical, and hybrid inheritance. It includes tasks to create classes with specific attributes and methods, as well as advanced topics like constructors, destructors, method overriding, polymorphism, and abstract classes. Additionally, it presents real-life scenarios such as banking systems, vehicle systems, library management, employee management, and student result systems to apply inheritance concepts.

Uploaded by

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

Practice Sheet

The document contains a practice sheet with various inheritance questions in programming, covering single, multilevel, multiple, hierarchical, and hybrid inheritance. It includes tasks to create classes with specific attributes and methods, as well as advanced topics like constructors, destructors, method overriding, polymorphism, and abstract classes. Additionally, it presents real-life scenarios such as banking systems, vehicle systems, library management, employee management, and student result systems to apply inheritance concepts.

Uploaded by

fatehx440
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Practice Sheet

Basic Inheritance Questions

1. Single Inheritance:
Question: Create a base class Person with attributes name and age. Derive a class
Student that has an additional attribute grade. Write a program to input and display
student details.
Variables:

o name (string)

o age (int)

o grade (char)

2. Multilevel Inheritance:
Question: Create a base class Animal with an attribute species. Derive a class
Mammal with an attribute furColor. Further, derive a class Dog with an attribute
breed. Write a program to input and display dog details.
Variables:

o species (string)

o furColor (string)

o breed (string)

3. Multiple Inheritance:
Question: Create a class Engine with an attribute horsepower. Create another class
Wheels with an attribute numWheels. Derive a class Car from both and add an
attribute brand. Write a program to input and display car details.
Variables:

o horsepower (int)

o numWheels (int)

o brand (string)

4. Hierarchical Inheritance:
Question: Create a base class Employee with attributes empID and name. Derive two
classes Manager and Developer. Manager has an additional attribute teamSize, and
Developer has programmingLanguage. Write a program to input and display details.
Variables:
o empID (int)

o name (string)

o teamSize (int)

o programmingLanguage (string)

5. Hybrid Inheritance:
Question: Create a class Device with attribute deviceName. Derive two classes
Computer and Mobile. Further, derive a class Smartphone from both Computer and
Mobile. Write a program to display details of a smartphone.
Variables:

o deviceName (string)

o processor (string)

o batteryLife (int)

Advanced Inheritance Questions

6. Constructor and Destructor in Inheritance (C++ Only):


Question: Create a base class Parent with a constructor and destructor displaying
messages. Derive a class Child and observe the constructor and destructor execution
order.
Variables:

o No specific attributes, just messages in constructors and destructors.

7. Method Overriding in Inheritance:


Question: Create a base class Shape with a function area(). Derive classes Circle and
Rectangle and override area() to calculate respective areas.
Variables:

o radius (double)

o length (double)

o width (double)

8. Polymorphism using Inheritance:


Question: Create a base class Employee with a function calculateSalary(). Derive
FullTimeEmployee and PartTimeEmployee, overriding calculateSalary() to implement
different salary calculations.
Variables:

o salary (double)
o hoursWorked (int)

o ratePerHour (double)

9. Abstract Class and Pure Virtual Functions:


Question: Create an abstract class Appliance with a pure virtual function turnOn().
Derive WashingMachine and Refrigerator and implement turnOn() accordingly.
Variables:

 brand (string)

 powerConsumption (int)

Real-Life Inheritance-Based Programs

11. Banking System:


Question: Create a base class Account with attributes accountNumber and balance.
Derive SavingsAccount and CurrentAccount, implementing deposit and withdrawal
operations.
Variables:

 accountNumber (int)

 balance (double)

 interestRate (double)

12. Vehicle System:


Question: Create a base class Vehicle with attributes model and year. Derive Car and
Bike with additional attributes. Implement a function to display details.
Variables:

 model (string)

 year (int)

 engineType (string)

13. Library Management:


Question: Create a base class Book with attributes title and author. Derive Fiction
and NonFiction with additional attributes.
Variables:

 title (string)

 author (string)

 genre (string)
14. Employee Management:
Question: Create a base class Employee with attributes empID and salary. Derive
Manager, Engineer, and Intern with specific methods.
Variables:

 empID (int)

 salary (double)

 department (string)

15. Student Result System:


Question: Create a base class Student with attributes name and rollNumber. Derive
Exam and Result classes to handle marks and final grade.
Variables:

 name (string)

 rollNumber (int)

 marks (array of int)

You might also like