Home > DeveloperSection > Interviews > What is final method in java?

Posted on    April-01-2015 12:34 AM

 Java Java 
 1 Answer(s)
  441  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Posted on    April-01-2015 12:52 AM

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();  

Output:Compile Time Error 

Don't want to miss updates? Please click the below button!

Follow MindStick