Single inheritence with constractor overriding and super keyword

 


#! single inheritence with constractor overriding and super keyword
"""
class Father:
    
    def __init__(self):
        self.money="1 lakh"
        print("This is parent class constractor")

    def show(self):
        print("This is parent class Instance method")
    
class Son(Father):
    def __init__(self):
        super().__init__()                      #use of super
        print("This son class constractor")

    def show(self):
        print("This is son class Instance method money:",self.money)
    
munna=Son()
munna.show()
"""
"""
Print Output:
This is parent class constractor
This son class constractor
This is son class Instance method money: 1 lakh
"""

###################################################################################
# NOW WITH ARGUMENT



class Father:
    sompotty="10 kata"
    def __init__(self,money1):
        self.money=money1
        print("This is parent class constractor")


    def show(self):
        print("This is parent class Instance method")






class Son(Father):
    def __init__(self,money1,job1):        ###### aivabe
        super().__init__(money1)       ####and aivabe
        self.job=job1
        print("This son class constractor")



    #instance mathod
    def show(self):
        print("This is son class Instance method")
        print(" money:",self.money)
        print("job:",self.job)
        # super diye class variable ke access korlam parent er
        print(super().sompotty)
        
    
munna=Son("10 lakh","python job")
munna.show()

print(munna.money)

print(munna.job)
print(munna.sompotty)



"""
Print Output:
This is parent class constractor
This son class constractor
This is son class Instance method
 money: 10 lakh
job: python job
10 kata

10 lakh
python job
10 kata
"""

Comments

Popular posts from this blog

D WEB LINK