class SelfCounter{
private static int counter;
private int id = counter ++;
public String toString(){
return "SelfCounter :" + id;
}
}
class WithFinalFields{
static final SelfCounter wffs = new SelfCounter();
final SelfCounter wff = new SelfCounter();
public String toString(){
return "wff = " + wff + "\n wffs = " + wffs;
}
}
public class E18_StaticFinal {
public static void main(String[] args) {
System.out.println("First Object :");
System.out.println(new WithFinalFields());
System.out.println("Second Object: ");
System.out.println(new WithFinalFields());
}
}
,运行结果是
First Object :
wff = SelfCounter :1
wffs = SelfCounter :0
Second Object:
wff = SelfCounter :2
wffs = SelfCounter :0 ,
final与static final的区别的例子
最新推荐文章于 2023-03-09 20:46:16 发布