WHAT IS FINAL VARIABLE IN JAVA?

Royce Roy

Total Post:51

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

    Post:807

    Points:4035
    What is final variable in java?

    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

Answer

NEWSLETTER

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