Research breakthrough possible @S-Logix pro@slogix.in

Office Address

  • 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
  • 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.

Sample 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
implement method overriding in python