Programming Pandit

c/c++/c#/Javav/Python


Latest Update

Tuesday, April 16, 2024

Program to illustrate the concept of method overriding in python.

Code: 

# Python program to demonstrate  

# method overriding 

  

  

# Defining parent class 

class Parent(): 

      

    # Constructor 

    def __init__(self): 

        self.value = "Inside Parent"

          

    # Parent's show method 

    def show(self): 

        print(self.value) 

          

# Defining child class 

class Child(Parent): 

      

    # Constructor 

    def __init__(self): 

        self.value = "Inside Child"

          

    # Child's show method 

    def show(self): 

        print(self.value) 

          

          

# Driver's code 

obj1 = Parent() 



obj2 = Child() 

  

obj1.show() 

obj2.show()


Output:





No comments:

Post a Comment