#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to implement method overriding in python?
Description

To implement method overloading in python3.

Process
Method overriding:

   Overriding is the ability of a class to change the implementation of a method provided by one of its ancestors.

   Through method overriding a class may "copy" another class, avoiding duplicated code.

   Method overriding is thus a strict part of the inheritance mechanism.

   Python method overriding occurs simply defining in the child class a method with the same name of a method in the parent class.

Sapmle Code

#parent class
class over:
def action(self):
print(‘parent class’)

#child class 1
class ride(over):
def action(self):
print(‘Child class’)

#child class 2
class override(over):
def action(self):
print(‘child class 2’)

#object creation
o = over()
r = ride()

#method calling statement
o.action()
r.action()

Screenshots