From d068a515b2816dd621a962b95eeae36166765571 Mon Sep 17 00:00:00 2001 From: Madhumitha Date: Mon, 27 Oct 2025 06:19:38 -0700 Subject: [PATCH] Add files via upload --- object oriented programing .py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 object oriented programing .py diff --git a/object oriented programing .py b/object oriented programing .py new file mode 100644 index 00000000..e4237761 --- /dev/null +++ b/object oriented programing .py @@ -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()}")