为什么我调用了子类的方法,给子类的属性赋了值,输出的结果却只为零
测试类 package imooc.com;public class Tt { public static void main(String[] args) { // TODO Auto-generated method stub AA aa=new AA(); AA n=new BB(); n.a=1;n.b=2; double d=n.Nn(); System.out.println(d); }}
类1
package imooc.com;
public class AA {
public double a;
public double b;
public double Nn(){
double s=0;
return s;
}
}
类2
package imooc.com;
public class BB extends AA {
public double a;
public double b;
public double Nn(){
double s=0;
s=a+b;
return s;
}
}