Java final class

If you make any class as final, you cannot extend it.


\begin{lstlisting}
final class Bike{}
\par
class Honda1 extends Bike{
void ru...
...g args[]){
Honda1 honda= new Honda1();
honda.run();
}
}
\end{lstlisting}

The output for the above snippet will be Compile Time Error. Final method is inherited but you cannot override it. For Example:


\begin{lstlisting}
class Bike{
final void run(){System.out.println(''running.....
... static void main(String args[]){
new Honda2().run();
}
}
\end{lstlisting}

The output for the above code snippet will be running....