运行结果,有点不懂呀,请教各位大神!!!
class Person {
//年龄
public static int age = 0;
//出生
Person(){}
//克隆人
Person(int age){
this.age = age;
}
//过了一年
public void grow(){
age++;
}
}
public class staticDemo {
Person p = new Person(10);
static Person p1,p2;
static{
System.out.println("p1.age =" + p1.age + ",p2.age =" + p2.age);
p1 = new Person(20);
System.out.println("p1.age =" + p1.age + ",p2.age =" + p2.age);
p2 = new Person(30);
System.out.println("p1.age =" + p1.age + ",p2.age =" + p2.age);
}
public static void main(String[] args) {
staticDemo sd = new staticDemo();
System.out.println("p.age =" + sd.p.age);
System.out.println("p1.age =" +p1.age + ",p2.age =" + p2.age);
p1.grow();
System.out.println("p1.age =" +p1.age + ",p2.age =" + p2.age);
System.out.println(sd.p.age);
}
}
|
|