class Dog: def bark(self): return "Woof!" dog = Dog() print(dog.bark())
Woof!
class Cat: def __init__(self, name): self.name = name def meow(self): return f"{self.name} says Meow!" cat = Cat("Whiskers") print(cat.meow())
Whiskers says Meow!
class Animal: def speak(self): return "Some sound" class Cow(Animal): def speak(self): return "Moo" cow = Cow() print(cow.speak())
Moo
class Animal: def speak(self): return "Some sound" class Cow(Animal): def speak(self): return super().speak() + " and Moo" cow = Cow() print(cow.speak())
Some sound and Moo
Copyright © 2023 - slash-root.com