Call Superclass Method Python
Well, now the thing is that when we have our own implementation for the eat method in the Lion class, it would call that eat method only, whenever called. But what if we need to call the eat method from the superclass, which is the Animal class? In short, we are going to have a look at what to do, if we need to call the method from the superclass, instead of the one, that is overriding.
The thing is that we are calling the Animal class a superclass. So here, we are going to use the super function, which would allow us to call the method from the superclass. Let’s have an example, which demonstrates the use of a super function to call the method from the superclass.
Call Superclass Method Python
As you can see, we have the doSomething method with the child class as well, but inside that, we are calling the doSomething method from the superclass. So, using the super function, we can simply call the superclass method.
Alternatively, we can do the same thing using the name of the class, which, we can call the doSomething method in this case.
As you can see, using the class name, we have called the method doSomething. In this case, as well, one argument is to be passed to the method. In this way, we can simply call the methods from the superclass, instead of calling the methods of the child class.