简单一个题
2. 1) class Super{
2) public float getNum(){return 3.0f;}
3) }
4)
5) public class Sub extends Super{
6)
7) }
which method, placed at line 6, will cause a compiler error?
A. public float getNum(){return 4.0f;}
B. public void getNum(){}
C. public void getNum(double d){}
D. public double getNum(float d){return 4.0d;}
Answer:B
为什么选它啊
------解决方案--------------------A. public float getNum(){return 4.0f;} //重写
B. public void getNum(){} //错误 方法名与父类同 ,而且参数相同,但返回类型不同是不行的
C. public void getNum(double d){}//重载
D. public double getNum(float d){return 4.0d;} ///重载