Home Tutorials Python OOP Concepts Method Overriding
Method Overriding

Method Overriding


20. Method Overriding

Method overriding happens when a child class provides its own version of a parent class method. This is one of the main ways polymorphism is implemented in Python OOP.

Syntax

class Child(Parent):
    def method(self):
        pass

Example

class Animal:
    def sound(self):
        print("Animal sound")

class Dog(Animal):
    def sound(self):
        print("Bark")

obj = Dog()
obj.sound()

Output

Bark
Example

🏋️ Test Yourself With Exercises

Take our quiz on Method Overriding to test your knowledge.

Browse Quizzes »