What is the final method in Java?
If we change any method to a final method, we can’t override it.
- class Bike{
- final void run(){System.out.println(“running”);}
- }
- class Honda extends Bike{
- void run(){System.out.println(“running safely with 100kmph”);}
- public static void main(String args[]){
- Honda honda= new Honda();
- honda.run();
- }
- }
Output:Compile Time Error
Recent Posts