Thursday 23 September 2021

Python: Method overriding

Child class can override the behaviour of parent class method. This technique is called method overriding.

 

Let’s see it with an example.

 

method_overriding._demo.py

class ParentClazz:
    def welcome(self):
        return "Hi!!!!!"

class ChildClazz(ParentClazz):
    def welcome(self):
        return "Good Morning!!!"

obj = ChildClazz()
print(obj.welcome())

Output

Good Morning!!!




 

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment