class A
{
protected double x=10,y=12.56;
public void speak()
{
System.out.println("我喜欢NBA");
}
public void cry()
{
y=x+y;
System.out.printf("y=%f\n",y);
}
}
class B extends A
{
int y=100,z;
public void speak()
{
z=2*y;
System.out.println("I love This Game");
System.out.printf("y=%d,z=%d",y,z);
}
}
class Example54
{
public static void main(String args[ ])
{
B b=new B();
b.cry();
b.speak();
}
}
为什么在这段程序中,当调用b.cry()方法的时候,y的值是12.56,而不是100?谢谢!
{
protected double x=10,y=12.56;
public void speak()
{
System.out.println("我喜欢NBA");
}
public void cry()
{
y=x+y;
System.out.printf("y=%f\n",y);
}
}
class B extends A
{
int y=100,z;
public void speak()
{
z=2*y;
System.out.println("I love This Game");
System.out.printf("y=%d,z=%d",y,z);
}
}
class Example54
{
public static void main(String args[ ])
{
B b=new B();
b.cry();
b.speak();
}
}
为什么在这段程序中,当调用b.cry()方法的时候,y的值是12.56,而不是100?谢谢!
cry()是父类的方法也要调用父类中的变量