Python Inheritance – Tasks
1. SINGLE LEVEL INHERITANCE
--------------------------------------------------
TASK 1:
Create a class Person with:
- variable name
- method show_name()
Create a class Student inheriting Person with:
- variable roll_no
- method show_student() that prints name and roll number
--------------------------------------------------
TASK 2:
Create:
- class Vehicle with method start()
- class Car with method drive()
Access both methods using Car object.
--------------------------------------------------
2. MULTILEVEL INHERITANCE
--------------------------------------------------
TASK 3:
Create classes:
- Company → method company_name()
- Department → method dept_name()
- Employee → method emp_details()
Create Employee object and access all methods.
--------------------------------------------------
TASK 4:
Create:
- Animal → eat()
- Mammal → walk()
- Dog → bark()
Access all methods using Dog object.
--------------------------------------------------
3. HIERARCHICAL INHERITANCE
--------------------------------------------------
TASK 5:
Create:
- Account → account_type()
- SavingsAccount → interest()
- CurrentAccount → overdraft()
Create objects for both child classes.
--------------------------------------------------
TASK 6:
Create:
- Employee → salary()
- Manager → bonus()
- Developer → coding()
Call parent method from both child classes.
--------------------------------------------------
4. MULTIPLE INHERITANCE
--------------------------------------------------
TASK 7:
Create Father and Mother classes with property methods.
Create Child class inheriting both and access both methods.
--------------------------------------------------
TASK 8 (Method Conflict):
Create:
- class A → show()
- class B → show()
- class C(A, B)
Create object of C and:
- call show()
- print [Link]()
--------------------------------------------------
5. HYBRID INHERITANCE
--------------------------------------------------
TASK 9:
Create:
- School → school_name()
- Teacher(School) → subject()
- Student(School) → roll_no()
- Monitor(Teacher, Student) → duty()
Access all methods using Monitor object.