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()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Inheritance

A

class Dog(Animal):
def speak(self):
print(f’{self.name} barks.’}

dog = Dog(‘Dog’)
dog.speak()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly