Object oriented Programming Flashcards
1
Q
Declare a class
A
class Animal:
def __init__(self.name):
self.name = name
def speak(self): print(f’{self.name} makes a noise.’}
dog = Animal(‘Dog’)
dog.speak()
2
Q
Inheritance
A
class Dog(Animal):
def speak(self):
print(f’{self.name} barks.’}
dog = Dog(‘Dog’)
dog.speak()