Inheritance
🧠Concept:
Child class inherits data + behavior from parent class.
💼 Real-world idea:
A Manager is an Employee but with extra privileges.
Creation Question
Create a base class Employee with attributes name, salary.
Create subclass Manager(Employee) with extra attribute department.
Add a method show_info() showing all details.
Debugging Question
class Vehicle:
def move(self):
print("Moving")
class Car(Vehicle):
def wheels():
print("4 wheels")
c = Car()
c.move()
c.wheels()
🎯 Bug: parameter error in subclass method.
** Polymorphism**
🧠Concept:
Same function name, different behavior per class.
💼 Real-world idea:
Payment method — can be through CreditCard, UPI, or Cash.
Creation Question
Create 3 classes:
CreditCard, UPI, and Cash — each with a pay(amount) method showing how payment is made.
Then loop through all and call .pay() — observe polymorphism.
Debugging Question
class Dog:
def speak(self):
print("Woof!")
class Cat:
def speak():
print("Meow!")
for pet in [Dog(), Cat()]:
pet.speak()
🎯 Bug: missing argument in one class’s method definition.
Top comments (0)