This assignment demonstrates the principles of Object-Oriented Programming (OOP) in Python through two activities:
- Class Design with Inheritance ๐๏ธ
- Polymorphism Challenge ๐ญ
The goal is to understand how to design classes, use constructors, apply inheritance, and implement polymorphism in real-world examples.
Task:
- Create a class representing something of your choice (Smartphone, Book, Superhero, etc.).
- Add attributes and methods to bring it to life.
- Use a constructor
__init__()to initialize values. - Implement inheritance to show how one class can extend another.
Example:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def introduce(self):
return f"Hi, I'm {self.name}, and I'm {self.age} years old."
class Superhero(Person):
def __init__(self, name, age, power):
super().__init__(name, age)
self.power = power
def use_power(self):
return f"{self.name} uses {self.power}! "
hero = Superhero("Spider-Man", 18, "Web Shooting")
print(hero.introduce())
print(hero.use_power())