method overriding in python by R4R Team

Method overriding-
-python method overriding occurs by simply defining in the child class a method with the same name of a method in the parent class.
-Function name is same in parent and child class.


#create parent class A
class A():
def function(self):
print("Function of class A")

#create child class B
class B(A):
def function(self):
print("Function of class B")



Function of class B

-In this program, we have a two class, one is parent class and one is child class that inherits the property of parent class.
- class A is a parent class
- class B is a child class
- Both class have same function names as 'function(self)', so this type of senerio is known as function overriding or method overriding.
- b=B(), here 'b' is an object of the child class B, and b.function() call the function of the child class not the parent function.

Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!