OCJP

Method Override in Python

Method Overriding is ‘Method with same name and same signature in Parent and Child Class. We can override methods in Python also. In that case Child class will have method with same name as parent class and no of parameters also will be same. Following example shows the Method Overiding.

class Parent:
    def show(self):
        print("Parent Class")
class Child(Parent):
    def show(self):
        super().show();
        print("Child Class")


C= Child()
C.show()

We can use super() to call method of Parent class from Child Class.

Leave a Reply

Your email address will not be published. Required fields are marked *


× How can I help you?