4、类Test1、Test2定义如下:
1.public class Test1 {
2. public float aMethod(float a,float b)throws IOException {
3. }
4. }
5. public class Test2 extends Test1{
6.
7. }
将以下哪种方法插入行6是不合法的。(BCD)考继承和异常之间的知识
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{ }
尽量说详细点 谢谢大家啦!!
1.public class Test1 {
2. public float aMethod(float a,float b)throws IOException {
3. }
4. }
5. public class Test2 extends Test1{
6.
7. }
将以下哪种方法插入行6是不合法的。(BCD)考继承和异常之间的知识
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{ }
尽量说详细点 谢谢大家啦!!
B 不是重写,合法
C 重写合法,规定父类没抛的异常子类也不能抛,但没规定父类抛出的子类一定要抛
D 不是重写,合法
但在myeclipse下 A选项编译出错 怎么解释??
A. 父类在先,子类在后 B. 子类在先,父类在后
C. 有继承关系的异常不能在同一个try程序段内 D. 先有子类,其他如何排列都无关 还有这个题
A. 捕获异常 B. 抛出异常 C. 声明异常 D. 嵌套异常
不是 A选项不是重写父类的方法 A是属于子类的一个方法 跟父类没有关系 在myeclipse下编译出错是不是因为同父类的方法同名啦啊?????高手们解答解答!!!
A:错误,原因,override的修饰符只能扩大不能缩小。
B,D:正确,原因,不是override,而是overwrite.
C:正确,override,抛出的捕获性异常,必须为父类异常或子类或不抛出。