Bear with me as I am getting started with Python.
Say I have a multiple inheritance scenario:
class Animal:
def __init__(self, Animal):
print(Animal, 'is an animal.');
class Mammal(Animal):
def __init__(self, mammalName):
print(mammalName, 'is a warm-blooded animal.')
super().__init__(mammalName)
class NonWingedMammal(Mammal):
def __init__(self, NonWingedMammal):
print(NonWingedMammal, "can't fly.")
super().__init__(NonWingedMammal)
class NonMarineMammal(Mammal):
def __init__(self, NonMarineMammal):
print(NonMarineMammal, "can't swim.")
super().__init__(NonMarineMammal)
class Dog(NonMarineMammal, NonWingedMammal):
def __init__(self):
print('Dog has 4 legs.');
super().__init__('Dog')
d = Dog()
Upon printing, I get this:
Dog has 4 legs.
Dog can't swim.
Dog can't fly.
Dog is a warm-blooded animal.
Dog is an animal.
When init() is getting called from Dog class, the init() of NonMarineMammal is called which makes sense since MRO starts with left-most base class for a child class in case of multiple inheritance.
Again, the init() of NonMarineMammal calls its super()'s init() which is Mammal.
So my confusion is why I got
Dog can't fly.
instead of
Dog is a warm-blooded animal.
Why the above order isn't followed? Is it something to do with init() function or the same behaviour stands for other methods as well?