Overriding

Overriding allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes.

Python Example

For more Python class related examples, see:

# Define a parent class.
class Rectangle( ):
    def __init__(self, length, breadth):
        self.length = length
        self.breadth = breadth
    def get_area(self):
        print(self.length*self.breadth)

# Define a subclass that inherits the parent class but has its own get_area() method.
class Square(Rectangle):
    def __init__(self, side):
        self.side = side
        Rectangle.__init__(self, side, side)
    def get_area(self):
        print(self.side*self.side)

# Instantiate the two classes.
rectangle = Rectangle(4,5)
square = Square(3)

# Use the base class get_area() method.
rectangle.get_area( )

# Use the sub class get_area() method.
square.get_area( )