WHAT IS FINAL METHOD IN JAVA?

Royce Roy

Total Post:51

Points:255
Posted by  Royce Roy
Java 
 474  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    What is final method in java?

    The final keyword in java is used to restrict the user. The java final keyword can be used in many context. Final can be:

    1. variable
    2. method
    3. class

    If you make any method as final, you cannot 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 

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!