Welcome to the Object-Oriented Programming (OOP) exercises! These hands-on tasks will help you solidify your understanding of key OOP concepts in Python. 🚀
🧩 Exercise 1: Create a Class
Define a Dog
class with attributes name
and breed
, and a method bark()
.
Example:
class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed
def bark(self):
return "Woof!"
🔄 Exercise 2: Inheritance
Create a Poodle
subclass that inherits from Dog
and adds a trim_hair()
method.
Hint: Use super()
to call the parent class constructor.
🌈 Exercise 3: Polymorphism
Implement a make_sound()
method in both Dog
and Cat
classes.
Example:
class Cat:
def make_sound(self):
return "Meow!"
📚 Expand Your Knowledge
Need more practice? Explore our Python Classes Introduction tutorial for foundational concepts!