Python | super() function with multilevel inheritance - GeeksforGeeks

 



class GFG1:
def __int__(self):
print('GFG1 init')

def sub_GFG(self, b):
print('GFG1:', b)


class GFG2(GFG1):
def __int__(self):
print('GFG2 init')

def sub_GFG(self, b):
print('GFG2:', b)
super().sub_GFG(b + 1)


class GFG3(GFG2):
def __int__(self):
print('GFG3 init')

def sub_GFG(self, b):
print('GFG3:', b)
super().sub_GFG(b + 1)


if __name__ == '__main__':
gfg = GFG3()
gfg.sub_GFG(10)


  

GFG3: 10

GFG2: 11

GFG1: 12

 



class GFG1:
def __init__(self):
print('GFG1 init')

def sub_GFG(self, b):
print('GFG1:', b)


class GFG2(GFG1):
def __init__(self):
print('GFG2 init')
super().__init__()

def sub_GFG(self, b):
print('GFG2:', b)
super().sub_GFG(b + 1)


class GFG3(GFG2):
def __init__(self):
print('GFG3 init')
super().__init__()

def sub_GFG(self, b):
print('GFG3:', b)
super().sub_GFG(b + 1)


if __name__ == '__main__':
gfg = GFG3()
print('')
gfg.sub_GFG(10)


 

GFG3 init

GFG2 init

GFG1 init

GFG3: 10

GFG2: 11

GFG1: 12