Example of method overriding

In this example, we have defined the run method in the subclass as defined in the parent class but it has some specific implementation. The name and parameter of the method are the same, and there is IS-A relationship between the classes, so there is method overriding.


\begin{lstlisting}
//Java Program to illustrate the use of Java Method Overridin...
... Bike2();//creating object
obj.run();//calling method
}
}
\end{lstlisting}

Output:


\begin{lstlisting}
Bike is running safely
\end{lstlisting}