OnlinePython

Method Overriding Exercise

Question 1 of 4

What happens when a child class defines a method with the same name as a parent method?

class Animal:
    def speak(self):
        return "Animal makes a sound"

class Dog(Animal):
    def speak(self):
        return "Dog barks"

dog = Dog()
print(dog.speak())  # What is printed?