class A{
int x,y;
void setXY(int x,int y){
this.x=x;
this.y=y;
}
int multiply(){
return x*y;
}
}
class B extends A{
int x,z;
B(int x,int z){
super();
this.x=x;
this.z=z;
}
int multiply(){
return x*y*z;
}
}
public class Test{
public static void main(String args[]){
B b=new B(6,9);
A a=new B(5,10);
a.setXY(10,20);
// a.z=30;
System.out.println("m="+a.multiply());
b.setXY(7,8);
b.z=10;
int m=b.multiply();
System.out.println("m="+m);
}
}
运行的时候会出现NosuchmethodError:setXY 为31的错误`
为什么会出现这样的错误`
求教`
int x,y;
void setXY(int x,int y){
this.x=x;
this.y=y;
}
int multiply(){
return x*y;
}
}
class B extends A{
int x,z;
B(int x,int z){
super();
this.x=x;
this.z=z;
}
int multiply(){
return x*y*z;
}
}
public class Test{
public static void main(String args[]){
B b=new B(6,9);
A a=new B(5,10);
a.setXY(10,20);
// a.z=30;
System.out.println("m="+a.multiply());
b.setXY(7,8);
b.z=10;
int m=b.multiply();
System.out.println("m="+m);
}
}
运行的时候会出现NosuchmethodError:setXY 为31的错误`
为什么会出现这样的错误`
求教`
父类和子类中对变量的设置不存在多态性么?
调用父类的setXY方法` 改动的只是父类的变量`
方法存在多态性` 变量不存在` 对吗?