class A {
public String i = null;
void setA(String a) {
i = a;
}
String getA() {
return i;
}
} class B extends A {
int k;
} public class test {
public static void main(String[] args) {
A superOb = new A();
B subOb = new B();
System.out.println("Contents of superOb: ");
superOb.setA("aaa");
System.out.println();
System.out.println("Contents of superOb: "+superOb.getA());
System.out.println("Contents of subOb: "+subOb.getA());
}
} 输出的结果中 为什么是:Contents of subOb: null 而不是 Contents of subOb: aaa
public String i = null;
void setA(String a) {
i = a;
}
String getA() {
return i;
}
} class B extends A {
int k;
} public class test {
public static void main(String[] args) {
A superOb = new A();
B subOb = new B();
System.out.println("Contents of superOb: ");
superOb.setA("aaa");
System.out.println();
System.out.println("Contents of superOb: "+superOb.getA());
System.out.println("Contents of subOb: "+subOb.getA());
}
} 输出的结果中 为什么是:Contents of subOb: null 而不是 Contents of subOb: aaa
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货