Write a python program to demonstrate method overriding

 In this source code example, we will write a python program to demonstrate method overriding.

Write a python program to demonstrate method overriding

# Python program to demonstrate
# method overriding


# Defining parent class
class Parent():
	
	# Constructor
	def __init__(self):
		self.value = "Inside Parent class"
		
	# Parent's show method
	def show(self):
		print(self.value)
		
# Defining child class
class Child(Parent):
	
	# Constructor
	def __init__(self):
		self.value = "Inside Child class"
		
	# Child's show method
	def show(self):
		print(self.value)
		
		
# Driver's code
obj1 = Parent()
obj2 = Child()

obj1.show()
obj2.show()

Output:

Inside Parent class
Inside Child class

Comments