In general, the super keyword can be used to call overridden methods, access hidden fields or invoke a superclass's constructor. When i try to run it as at the end of the file i get this stacktrace Super() lets you avoid referring to the base class explicitly, which can be nice
Leon R34 by Lex974 on DeviantArt
But the main advantage comes with multiple inheritance, where all sorts of fun stuff can happen.
In fact, multiple inheritance is the only case where super() is of any use
I would not recommend using it with classes using linear inheritance, where it's just useless overhead. As for chaining super::super, as i mentionned in the question, i have still to find an interesting use to that For now, i only see it as a hack, but it was worth mentioning, if only for the differences with java (where you can't chain super). I'm currently learning about class inheritance in my java course and i don't understand when to use the super() call
I found this example of code where super.variable is used When do you call super() in java I see it in some constructors of the derived class, but isn't the constructors for each of the parent class called automatically Why would you need to use super?
So i was following python's super considered harmful, and went to test out his examples
Super() is how the parent or super class constructor for a java class is invoked in a derived class There was a fair amount of churn in the terminology during the first years of object oriented programming as various people worked in the area and published papers and books and developed object oriented languages. If we're using a class method, we don't have an instance to call super with Fortunately for us, super works even with a type as the second argument
Which is exactly what python tells me is not possible by saying that do_something () should be called with an instance of b. I wrote the following code