super can be used to invoke parent class method

The super keyword can also be used to invoke parent class method. It should be used if subclass contains the same method as parent class. In other words, it is used if method is overridden.


\begin{lstlisting}
class Animal{
void eat(){System.out.println(''eating...'');...
... void main(String args[]){
Dog d=new Dog();
d.work();
}
}
\end{lstlisting}

Output:


\begin{lstlisting}
eating...
barking...
\end{lstlisting}

n the above example Animal and Dog both classes have eat() method if we call eat() method from Dog class, it will call the eat() method of Dog class by default because priority is given to local. To call the parent class method, we need to use super keyword.