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

Inheritance

Uploaded by

Mizash Kandel
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)
10 views2 pages

Inheritance

Uploaded by

Mizash Kandel
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

Full-Day Inheritance Task Plan

(Python)
Part 1 – Basic Inheritance (Warm-up)
1. Single Inheritance Example

Create a Vehicle class with attributes brand and speed and a method move() .

Inherit it in a Car class, add an attribute num_doors , and method honk() .

Task: Instantiate Car and call both parent and child methods.

2. Modify Parent Property

Add a method in Car to change brand (inherited attribute).

Task: Update the brand from the child and show the change.

Part 2 – Using super()


1. Add an __init__() method in Vehicle with brand and speed .

2. Add Car with its own __init__() using super() to call Vehicle 's constructor.

3. Task: Extend it to ElectricCar with battery capacity. Show constructor chaining.

Part 3 – Method Overriding


1. Override the move() method in Car to show: "Car is moving at X km/h" .

2. Keep the original behavior in some cases using super().move() .

3. Task: Demonstrate both overridden and original methods.

Part 4 – Multiple Inheritance


1. Create a GPS class with method show_location() .

2. Make a SmartCar that inherits from both Car and GPS .

3. Task: Show how the method resolution order (MRO) works.

Full-Day Inheritance Task Plan (Python) 1


Part 5 – Multilevel Inheritance
1. Vehicle → Car → SportsCar

2. Add unique methods for each class.

3. Task: Instantiate SportsCar and access methods from all levels.

Part 6 – Hierarchical Inheritance


1. Vehicle as parent, Bike and Truck as children.

2. Add different attributes for each child.

3. Task: Demonstrate each child's unique behavior.

Part 7 – Real-World Mini Project


Theme: Zoo Management System

Animal (Parent) → attributes: name , age , species ; method: eat()

Lion (Child) → method: roar()

Elephant (Child) → method: spray_water()

ZooKeeper (Independent class) → feeds animals

Task:

1. Create multiple animals.

2. Feed them using the ZooKeeper class.

3. Add another layer (e.g., WildLion inherits from Lion ) and override behavior.

Full-Day Inheritance Task Plan (Python) 2

You might also like