Java final variable
Java final variable
If you make any variable
as final, you cannot change the value of final variable(It will be constant).
Example of final variable
There is a final variable speed limit, 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.
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
Comments
Post a Comment