问题: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。C中方法的返回类型应该和父类一致。对于一个方法来说,方法名/方法的参数类型/返回类型是决定方法的要素。
 |