Following is a code where I have tried to change the value of a final variable. First it prints "a" then "ab". So, if we can change the value of a final variable then what's the benefit of declaring a variable as final? what is use of final key word then? Please any one can help me with this?????
package test_new;
public class FinalVarValueChange {
public static void main(String[] args){
final StringBuffer s=new StringBuffer("a");
System.out.println("s before appending :"+s);
s.append("b");
System.out.println("s after appending :"+s);
}
}