发布时间 : 星期五 文章java期末考试题更新完毕开始阅读
D、interface B { void print();}
M、下面哪个函数是public?void? aMethod(){...}的重载函数?( D )
A、void? aMethod(?){...} B、public?int? aMethod(){...} C、public?void? aMethod ( ){...} D、public?int? aMethod?(?int?m){...}
N、A派生出子类B?,B派生出子类C,并且在Java源代码中有如下声明:
1.A a0=new A();
2.A? a1 =new B();
3.A a2=new C();
问以下哪个说法是正确的??( ) A、只有第1行能通过编译
?
B、第1、2行能通过编译,但第3行编译出错 C、第1、2、3行能通过编译,但第2、3行运行时出错 D、第1行、第2行和第3行的声明都是正确的?
O、假设A类有如下定义,设a是A类的一个实例,下列语句调用哪个是错误的?class A
{ int i;
D )(
static String s;
void method1() { }
static void method2() { }
}
P、有如下代码段:
1)
2) { if(unsafe()){//do something…}
3) else if(safe()){//do the other…}
4) }
其中,方法unsafe() 将抛出IOException, 请问可将以下哪项填入第1行?(A、public IOException methodName()
B、public void methodName()
C、public void methodName() throw IOException D、public void methodName() throws IOException
一、 程序阅读
1、写出以下程序的运行结果。
public class EqualOrNot
D )
{ public static void main(String[] args)
{ B b1=new B(5);
B b2=new B(5);
.equals(b2));
}
}
class B
{ int x;
B( int y){ x=y; }
}
2、写出以下程序的运行结果。
import java.io.*;
public class TestString
{ public static void main(String args[ ])
{ StringC s = new StringC (\
}
class StringC {
String s1;
String s2;
StringC( String str1 , String str2 )
{ s1 = str1; s2 = str2; }
public String toString( )
{ return s1+s2;}
}
3、写出以下程序的功能。
import java.io.*;
public class C {
public static void main(String[] args) throws IOException {
File inputFile = new File(“a.txt\
File outputFile = new File(“b.txt\
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read() ) != -1) out.write(c);