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

Posted on    March-31-2015 12:46 AM

 Java Java 
Ratings:
 1 Answer(s)
  501  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Points:4035
Posted on    March-31-2015 1:02 AM

If you make any variable as final, you cannot change the value of final variable(It will be constant).

There is a final variable speedlimit, we are going to change the value of this variable, but It can't be changed because final variable once assigned a value can never be changed.

class Bike9{  
 final int speedlimit=90;//final variable  
 void run(){  
  speedlimit=400;  
 }  
 public static void main(String args[]){  
 Bike9 obj=new  Bike9();  
 obj.run();  
 }  
}//end of class  

Output:Compile Time Error

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

Follow MindStick