当前位置: 技术问答>java相关
请为我解释一下这条题目,谢谢
来源: 互联网 发布时间:2014-12-29
本文导语: 33. Consider the classes defined below: import java.io.*; class Super { int methodOne( int a, long b ) throws IOException { // code that performs some calculations } float methodTwo( char a, int b ) { // code that performs other calcul...
33. Consider the classes defined below:
import java.io.*;
class Super
{
int methodOne( int a, long b ) throws IOException
{ // code that performs some calculations
}
float methodTwo( char a, int b )
{ // code that performs other calculations
}
}
public class Sub extends Super
{
}
Which of the following are legal method declarations to add to the class Sub? Assume that each method is the only one being added.
a) public static void main( String args[] ){}
b) float methodTwo(){}
c) long methodOne( int c, long d ){}
d) int methodOne( int c, long d ) throws ArithmeticException{}
e) int methodOne( int c, long d ) throws FileNotFoundException{}
我的答案是 a b d e
正确答案是 a b e
为什么 d 是错的,谢谢
import java.io.*;
class Super
{
int methodOne( int a, long b ) throws IOException
{ // code that performs some calculations
}
float methodTwo( char a, int b )
{ // code that performs other calculations
}
}
public class Sub extends Super
{
}
Which of the following are legal method declarations to add to the class Sub? Assume that each method is the only one being added.
a) public static void main( String args[] ){}
b) float methodTwo(){}
c) long methodOne( int c, long d ){}
d) int methodOne( int c, long d ) throws ArithmeticException{}
e) int methodOne( int c, long d ) throws FileNotFoundException{}
我的答案是 a b d e
正确答案是 a b e
为什么 d 是错的,谢谢
|
因为ArithmeticException不是IOException的子,而FileNotFoundException是IOException的子。
|
因为FileNotFoundException extends IOException
而ArithmeticException 不是
而ArithmeticException 不是
|
分呢?