What is the final variable in Java?

In Java, the final variable is used to restrict the user from updating it. If we initialize the final variable, we can’t change its value. In other words, we can say that the final variable once assigned to a value, can never be changed after that. The final variable which is not assigned to any value can only be assigned through the class constructor.

 

  1. class Bike9{
  2.  final int speedlimit=90;//final variable
  3.  void run(){
  4.   speedlimit=400;
  5.  }
  6.  public static void main(String args[]){
  7.  Bike9 obj=new  Bike9();
  8.  obj.run();
  9.  }
  10. }//end of class
Output:Compile Time Error