请高手帮我看看一个继承的问题
public class A {String s="[a]";
String gets()
{return s;}
}
public class B extends A
{
String s="[b]";
String gets() {return s;}
}
public class ploytest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
A a=new A();
B b=new B();
a.s="[aa]";
b.s="[bb]";
a=b;
System.out.println(a.s);
System.out.println(b.s);
System.out.println(a.gets());
System.out.println(b.gets());
((A)b).s="[aa]";
System.out.println(a.s);
System.out.println(b.s);
System.out.println(a.gets());
System.out.println(b.gets());
}
}
为什么结果是这样:
[a]
[bb]
[bb]
[bb]
[aa]
[bb]
[bb]
[bb]
请帮分析一下吧,谢谢了