标签:
classPerson{
staticint i;
}
classTest{
publicstaticvoid main(String args []){
Person p1 =newPerson();
Person p2 =newPerson();
Person.i =10;
System.out.println("p1的i的值为"+ p1.i);
System.out.println("p2的i的值为"+ p2.i);
p1.i =20;
System.out.println("p1的i的值为"+ p1.i);
System.out.println("p2的i的值为"+ p2.i);
}
}
classPerson{
staticString name;
staticvoid talk(){
System.out.println("my name is "+ name);
}
}
classTest{
publicstaticvoid main(String args []){
Person.name ="ZhangSan";
Person.talk();
}
}
classPerson{
static{
System.out.println("静态代码块");
}
staticString name;
staticvoid talk(){
System.out.println("my name is "+ name);
}
}
classTest{
publicstaticvoid main(String args []){
Person.name ="ZhangSan";
Person.talk();
}
}
标签:
原文地址:http://www.cnblogs.com/arroneve/p/5815430.html