public class A {
    public static void main(String[] args) throws Exception {
ReadFile file = null;
Properties fileContent = null;
try {
    // read test file content.
    file = new ReadFile(FILE);
    // file is exist.
   if (file.init()) {
         B b = new B();
fileContent = file.getHeads();
b = setb(fileContent);
System.out.println("super bb="+b.getAlgorithm());
C c = new C();
System.out.println("client aa="+c.getAlgorithm());
}
} catch(Exception e) {
System.out.println("error="+e);
throw e;
}
}
其中C类是继承是B类的,我认为在b = setb(fileContent);这个函数中已经给B的对象进行了复值的操作,为什么b.getAlgorthm()可以得到的内容但是继承自他的C  中c.getAlgorithm();就不能得到内容呢?? 请大家帮忙,谢谢各位了!

解决方案 »

  1.   

    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());
    }

    同样的问题 这个看的比较清楚 之前的太复杂了
      

  2.   

    你的subOb和superOb 不是同一个对象,superOb.setA("aaa");  只是设置superOb这个对象的 i成员为"aaa",跟subOb没有关系.楼主刚入门吧,加油!