System.out.println(javaFiles[i]);
}
}
代码中JavaFilter类的代码为:
A.publicclassJavaFilterimplementsFilenameFilter{
publicvoidaccept(Filedir,Stringname){
returnname.endsWith(".txt");
}
}
B.publicclassJavaFilterimplementsFilenameFilter{
publicbooleanaccept(Filedir,Stringname){
returnname.endsWith(".txt");
}
}
C.publicclassJavaFilterextendsFilenameFilter{
publicbooleanaccept(Filedir,Stringname){
returnname.endsWith(".txt");
}
}
D.publicclassJavaFilterextendsFilenameFilter{
publicvoidaccept(Filedir,Stringname){
returnname.endsWith(".txt");
}
}
5.下列关于序列化和反序列化描述正确的是
A.序列化是将数据转换为n个byte序列的过程
B.反序列化是将n个byte转换为一个数据的过程
C.将类型int转换为4byte是反序列化过程
D.将8个字节转换为long类型的数据是序列化过程
6.请看下列代码:
interfaceFoo{
}
classAlphaimplementsFoo{
}
classBetaextendsAlpha{
}
publicclassDeltaextendsBeta{
publicstaticvoidmain(String[]args){
Betax=newBeta();
<插入代码>
}
}
在<插入代码>处,填入下列代码,运行时能引起java.lang.ClassCastException异
常的是:
A.Alphaa=x;
B.Foof=(Delta)x;
C.Foof=(Alpha)x;
D.Betab=(Beta)(Alpha)x;
7.请看下列代码:
1:
publicclassFoo{
2:
publicstaticvoidmain(String[]args){
3:
try{
4:
Aa=newA();
5:
a.method1();
6:
}catch(Exceptione){
7:
System.out.print("anerroroccurred");
8:
}
9:
}
10:
}
1:
classA{
2:
publicvoidmethod1(){
3:
Bb=newB();
4:
b.method2();
5:
System.out.println("methodone");
6:
}
7:
}
1:
classB{
2:
publicvoidmethod2(){
3:
Cc=newC();
4:
c.method3();
5:
System.out.println("methodtwo");
6:
}
7:
}
1:
classC{
2:
publicvoidmethod3(){
3:
System.out.println("methodthree");
4:
thrownewNullPointerException();
5:
}
6:
}
关于上述代码说法正确的是:
A.Foo类的第7行将被执行
B.A类的第5行将被执行
C.B类的第5行将被执行
D.C类的第3行将被执行
8.请看下列代码:
publicclassA{
publicStringsayHello(Stringname)throwsTestException{
if(name==null){
thrownewTestException();
}
return"Hello"+name;
}
publicstaticvoidmain(String[]args)throwsTestException{
Aa=newA();
System.out.println(a.sayHello(null));
}
}
classTestExceptionextendsException{
}
关于上述代码说法正确的是:
A.A类编译失败
B.代码"System.out.println(a.sayHello("John"));"行,会抛出未检查异常
TestException
C.代码"Aa=newA();"行,会抛出未检查异常TestException
D.代码"System.out.println(a.sayHello("John"));"行,会抛出已检查异常
TestException
9.请看下列代码:
1.//somecodehere
2.try{
3.//somecodehere
4.}catch(SomeExceptionse){
5.//somecodehere
6.}finally{
7.//somecodehere
8.}
下面哪三种情况能使第7行的代码执行:
A.第3行抛出异常
B.第1行抛出异常
C.第5行抛出异常
D.第3行代码成功执行
10.以下说法错误的是:
A.try…catch..catch,多个catch时,后一个catch捕获类型一定是前一个的父类
B.try….finally可以组合使用
C.throw抛出一些异常,程序不进行处理,程序编译也无错误
D.throws一定是写在方法后面
11.下列代码运行的结果是:
publicclassA{
publicvoidprocess(){
System.out.print("A");
}
publicstaticvoidmain(String[]args){
try{
((A)newB()).process();
}catch(Exceptione){
System.out.print("Exception");
}
}
}
classBextendsA{
publicvoidprocess()throwsRuntimeException{
super.process();
if(true)
thrownewRuntimeException();
System.out.print("B");
}
}
A.Exception
B.AException
C.AExceptionB
D.ABException
12.下列代码实现的功能是:
FileOutputStreamfos=newFileOutputStream("system.txt",true);
PrintStreamps=newPrintStream(fos);
System.setOut(ps);
System.out.println("writer");
A.向控制台打印“writer”,可以实现追加打印
B.向控制台打印“writer”,但是不可以实现追加打印
C.向文件system.txt写“writer”,但是不可以实现追加写
D.向文件system.txt写“writer”,可以实现追加写
13.在Java中,下面的代码会出现编译错误的是:
A.Filef=newFile("/","autoexec.bat");
B.DataInputStreamdin=new