class Parent{
static int ii= 1;
int i = 1;
public int getInt(){
return i;
}
public int getStaticInt(){
return ii;
}
}
class Child extends Parent{
static int ii= 2;
int i = 2;
public int getInt(){
return i;
}
public int getStaticInt(){
return ii;
}
}
public class Test2 {
public static void main(String args[]){
Parent p = new Child();
System.out.print(p.i);
System.out.print(p.ii);
System.out.print(p.getInt());
System.out.println(p.getStaticInt());
Child c = (Child) p;
System.out.print(c.i);
System.out.print(c.ii);
System.out.print(c.getInt());
System.out.print(c.getStaticInt());
}
}
输出结果:
1122
2222
实例变量 i,与类变量 ii 都不具有多态性。
分享到:
评论