单项选择题
定义类A及类中的方法getVar(),定义类A的子类B,若要在类B中覆盖同名方法,下面正确的定义是?
class A{
private float x=1.0f;
protected float getVar(){ return x; }
}
class B extends A{
private float x=2.0f;
//覆盖类A中的同名方法的代码放在此处
}
A float getVar(){return x;}
B protected float getVar(float y){return x+y;}
C protected float getVar(){return x;}
D public float getVar(){return x;}