Programming with Python

  1. Home
  2. Docs
  3. Programming with Python
  4. OOPs concept in Python
  5. Overriding in Python

Overriding in Python

Essential features of object oriented programming:-

  • Data Encapsulation
  • Inheritance
  • Overriding
  • Polymorphism

Overriding- Overriding is the feature which lets you define a parent class method. Like the name suggests, you can overriding a parent class function or a method in the child class.

Following conditions must be met for overriding a function:

  1. Inheritance should be there. Function overriding cannot be done within a class. We need to derive a child class from a parent class.
  2. The function that is redefined in the child class should have the same signature as in the parent class i.e. same number of parameters.

e.g.,

class company1():
    def employee(self, a):
        print("This is a parent class.")

class company2(a):
    def employee(self):
        print("Employees work")

a=company2()
a.employee()
Output- Employees work

This is all about overriding in python.

Was this article helpful to you? Yes No

How can we help?