0% found this document useful (0 votes)
17 views2 pages

Sheet 2

Uploaded by

norantharwat58
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 views2 pages

Sheet 2

Uploaded by

norantharwat58
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
You are on page 1/ 2

Sheet2

Exercise 1: Animal Inheritance


a) Create a base class Animal with attributes like name, species, and age.
b) Create subclasses Dog, Cat, and Bird that inherit from Animal.
c) Add specific attributes to each subclass (e.g., breed for Dog, color for Cat, wingspan
for Bird).
d) Implement methods like make_sound() and eat() in the base class and override
them in subclasses if necessary.
e) Create instances of each subclass and test their methods and attributes.
Exercise 2: Vehicle Inheritance
a) Create a base class Vehicle and ElectricVehicle.
b) Create a subclass HybridVehicle that inherits from both Vehicle and ElectricVehicle.
c) Implement methods like start_engine() and charge_battery() in the appropriate
classes.
Exercise 3: Employee Inheritance
d) Create a base class Employee with attributes like name, id, and salary.
e) Create subclasses Manager, Developer, and Salesperson that inherit from
Employee.
f) Add specific attributes to each subclass (e.g., department for Manager,
programming_language for Developer, target_sales for Salesperson).
g) Implement methods like calculate_bonus() and work_hours() in the base class and
override them in subclasses if necessary.
h) Create instances of each subclass and test their methods and attributes.
Exercise 4: Shape Inheritance
a) Create a base class Shape with attributes like color and filled.
b) Create subclasses Circle, Rectangle, and Triangle that inherit from Shape.
c) Add specific attributes to each subclass (e.g., radius for Circle, width and height for
Rectangle, base and height for Triangle).
d) Implement methods like calculate_area() and calculate_perimeter() in the base
class and override them in subclasses.
e) Create instances of each subclass and test their methods and attributes.

You might also like