java - Final static can be changed? -
i wrote code trying change see happening.
in object class field,
static final string msg="here";
and in same object, in methot
public void givemessage(int no) { system.out.println("look."); system.out.println(msg); }
here gives "here" when call main. but
public void names(string[] names) { string msg=" - "; system.out.println(msg); }
here when call main gives -, not "here" final static. why did change , why there no compile error? or misunderstood java?
you using 2 different variables, class variable immutable (final) local 1 not, have same name not same.
if want verify this, put in main method myclassname.msg="-" , you'll see compiler complain.
Comments
Post a Comment