区别:分配空间时间
static final java程序一运行就为常量分配空间;
final 行到此才分配空间
相同:修饰对象时,可以改变对象内部成员;即一个引用初始化指向一个对象就不能改指向另一个对象( 只能new()一次不能再new()),但可以修改对象本身
public class Practice07 {
static final Constan constant =new Constan();
final Constan constan =new Constan();
public static void main(String[] args) {
Practice07 pra6 =new Practice07();
}
public Practice07() {
// TODO Auto-generated constructor stub
constan.setStr("final constant chang successfully");
constant.setStr("static final constant chang successfully");
constant.s="constant";
constan.s="constan";
System.out.println("static final-s="+constant.s);
System.out.println("final-s="+constan.s);
}
}
class Constan{
String s="s";
Constan() {
// TODO Auto-generated constructor stub
System.out.println("Constan.Constan()");
}
String getStr() {
// TODO Auto-generated method stub
return s;
}
void setStr(String t) {
// TODO Auto-generated method stub
s=t;
System.out.println("Constan.setStr()");
System.out.println("s="+s);
}
}
Constan.Constan()
Practice07.main()
Constan.Constan()
Constan.setStr()
s=final constant chang successfully
Constan.setStr()
s=static final constant chang successfully
static final-s=constant
final-s=constan