作业帮 > 综合 > 作业

java,谢谢15. 类Test1、Test2定义如下:1. public class Test12.{ public

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/21 08:14:16
java,谢谢
15. 类Test1、Test2定义如下:
1. public class Test1
2.{ public float aMethod(float a,float b) throws
3. IOException { }
4. }
5. public class Test2 extends Test1{
6.
7.}
将以下哪种方法插入行6是不合法的。( )
A、float aMethod(float a,float b){ }
B、public int aMethod(int a,int b)throws Exception{ }
C、public float aMethod(float p,float q){ }
D、public int aMethod(int a,int b)throws IOException{ }
为什么选A?谢谢。
Test2是Test1的子类,在子类重写(注意与重载不同)父类的方法,不能够降低该方法的访问权限。
所以A是不对的。父类该方法的访问权限是public,也就是所有类都可以访问,
而A中的是包访问,也就是说只有同一个包中的可以访问,降低了访问权限是不对的。
希望能帮到你,仍有问题可以HI我~!