Wednesday, 20 June 2018

Python Program To demonstrate inheritance.

# Python Program To demonstrate inheritance.

# Parent Class
class parentCls:
    def __init__(self):
        print("Parent Class Constructor.")

    # definition   of Parent class methods
    def prntMethd_1(self):
        print("I am parent class method 1.")
    def prntMethd_2(self):
        print("I am parent class method 2.")

# Child Class
class childCls(parentCls):  # inherit to parent class
    def __init__(self):
        print("Child class constructor.")

    # definition   of child class methods
    def childMethd_1(self):
        print("I am child class method 1")
    def childMethd_2(self):
        print("I am child class method 2")

c = childCls()  # Child class instance

c.childMethd_1()    # child call it's method
c.childMethd_2()    # Again child call it's method
c.prntMethd_1()     # child call it's Parent class method
c.prntMethd_2()     # Again child call it's Parent class method

input("Press Enter to Exit")

No comments:

Post a Comment

Popular Posts