If a field is declared static, there exists exactly one incarnation of the field, no matter how many instances (possibly zero) of the class may eventually be created. A static field, sometimes called a class variable, is incarnated when the class is initialized (§12.4).A field that is not declared static (sometimes called a non-static field) is called an instance variable. Whenever a new instance of a class is created, a new variable associated with that instance is created for every instance variable declared in that class or any of its superclasses.
无论你new TestBean几次...只有一个static变量在内存中!
2 应该是类被连接时的准备阶段吧。
TestBean{
public static String url="XXX";
TestBean(){
}
TestBean(String s){
url =s;
}
}
第一次:new TestBean()...结果:TestBean.url="XXX"
第二次:new TestBean("TTT")....结果:TestBean.url="TTT"
第三次:new TestBean()...结果:TestBean.url=????第3次的结果是什么呢???