final variable: you can not change the value of final variable

Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)

1080

Program:


 class FinalVariable{
 final int age=70;//final variable
 void changeage(){
  age=40;
 }
 public static void main(String args[]){
 FinalVariable obj=new  FinalVariable();
 obj.changeage();
 }
}//end of class



/* There is a final variable age, 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.
 */

Output:

Output:Compile Time Error
cannot assign a value to final variable age
  age=40;
  ^
1 error

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.