From 5427e951f03734cc55797a62843928681665d68d Mon Sep 17 00:00:00 2001 From: Madhumitha Date: Thu, 30 Oct 2025 20:50:47 +0530 Subject: [PATCH] Add inheritance and method overriding example add inheritance and method overriding --- object oriented programing | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 object oriented programing diff --git a/object oriented programing b/object oriented programing new file mode 100644 index 00000000..7ee64958 --- /dev/null +++ b/object oriented programing @@ -0,0 +1,24 @@ +# Task #32: Inheritance and Method Overriding Example + +class Animal: + def __init__(self, name): + self.name = name + + def sound(self): + return "Some generic animal sound" + +# Dog inherits from Animal +class Dog(Animal): + def sound(self): + return "Woof! Woof!" + +# Cat inherits from Animal +class Cat(Animal): + def sound(self): + return "Meow!" + +# Demonstration +animals = [Dog("Buddy"), Cat("Kitty"), Animal("Creature")] + +for animal in animals: + print(f"{animal.name} says: {animal.sound()}")