From 776fb477101eab82060ecd745f4d5f112a4cc754 Mon Sep 17 00:00:00 2001 From: 23046273 Date: Tue, 9 Jun 2026 11:37:45 +0100 Subject: [PATCH 1/2] animal --- code | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 code diff --git a/code b/code new file mode 100644 index 00000000..727a4aa7 --- /dev/null +++ b/code @@ -0,0 +1,45 @@ + +class Animal: + def __init__(self, name, sound): + self.name = name + self._sound = sound + +def makeSound(self): + print(f"{self._name} makes {self._sound}") + +class Seal(Animal): + def __init__(self): + super().__init__("Seal", "Screech") + +goofy = Dog() +goofy.makeSound() +daffy = Duck() +daffy.makeSound +salty = Seal() +salty.makeSound + + + +# polymorphism +animals = [] + +animals.append(goofy) +animals.append(daffy) +animals.append(salty) + +for animal in animals: + animal.makeSound() + + + + + + + + + + + + + + \ No newline at end of file From 471d16e95449c5f75c0ea99682f704a125ead137 Mon Sep 17 00:00:00 2001 From: 23046273 Date: Tue, 9 Jun 2026 13:19:02 +0100 Subject: [PATCH 2/2] overloading method --- code | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/code b/code index 727a4aa7..ce68823b 100644 --- a/code +++ b/code @@ -1,11 +1,24 @@ class Animal: def __init__(self, name, sound): - self.name = name + self._name = name self._sound = sound -def makeSound(self): - print(f"{self._name} makes {self._sound}") + def makeSound(self): + print("Hello") + + +class Dog(Animal): + def __init__(self): + super().__init__("Dog", "Bark") + +lassy = Dog() +lassy.makeSound() + + +class Duck(Animal): + def __init__(self): + super().__init__("Duck", "Quack") class Seal(Animal): def __init__(self): @@ -18,8 +31,6 @@ daffy.makeSound salty = Seal() salty.makeSound - - # polymorphism animals = [] @@ -36,6 +47,37 @@ for animal in animals: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +