class A {
double f(double x,double y) {
return x+y;
}
static int g(int n) {
return n*n;
}
}
class B extends A {
double f(double x,double y) {
double m=super.f(x,y);
return m+x*y;
}
static int g(int n) {
int m=A.g(n); //继承中类方法该怎么处理
return m+n;
}
}
public class Test5_3_3 {
public static void main(String[] args) {
B b=new B();
System.out.println(b.f(10.0,8.0));
System.out.println(b.g(3));
A a=new B();
System.out.println(a.f(10.0,8.0));
System.out.println(a.g(3)); //输出结果:9 (不懂)
}
}
代码如上,标注的那一行代码我以为结果是“12”的,不太懂这个继承子类中,类方法是咋回事?