Java基础面试题Word文件下载.docx
- 文档编号:14947881
- 上传时间:2022-10-26
- 格式:DOCX
- 页数:12
- 大小:17.86KB
Java基础面试题Word文件下载.docx
《Java基础面试题Word文件下载.docx》由会员分享,可在线阅读,更多相关《Java基础面试题Word文件下载.docx(12页珍藏版)》请在冰豆网上搜索。
d:
\\"
"
file.txt"
);
try{
<
填入代码>
}catch(Exceptione){
e.printStackTrace();
}
A.BufferedWriterbw=newBufferedWriter(newFileWriter(file));
bw.write("
HelloWorld"
bw.close();
if(file.exists()){
file.delete();
B.BufferedWriterbw=newBufferedWriter(newFileWriter(file));
file.deleteFile();
C.BufferedWriterbw=newBufferedWriter(file);
D.BufferedWriterbw=newBufferedWriter(file);
4.题目代码功能为:
打印扩展名为txt的文件
publicstaticvoidmain(String[]args){
Stringdir="
/javalesson"
;
FilecurrDir=newFile(dir);
FilenameFilterfilter=newJavaFilter();
String[]javaFiles=currDir.list(filter);
for(inti=0;
i<
javaFiles.length;
i++){
System.out.println(javaFiles[i]);
代码中JavaFilter类的代码为:
A.publicclassJavaFilterimplementsFilenameFilter{
publicvoidaccept(Filedir,Stringname){
returnname.endsWith("
.txt"
}
B.publicclassJavaFilterimplementsFilenameFilter{
publicbooleanaccept(Filedir,Stringname){
C.publicclassJavaFilterextendsFilenameFilter{
D.publicclassJavaFilterextendsFilenameFilter{
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:
3:
4:
Aa=newA();
5:
a.method1();
6:
7:
System.out.print("
anerroroccurred"
8:
9:
10:
classA{
publicvoidmethod1(){
Bb=newB();
b.method2();
System.out.println("
methodone"
classB{
publicvoidmethod2(){
Cc=newC();
c.method3();
methodtwo"
classC{
publicvoidmethod3(){
methodthree"
thrownewNullPointerException();
关于上述代码说法正确的是:
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.代码"
行,会抛出未检查异常TestException
D.代码"
行,会抛出已检查异常
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.下列代码运行的结果是:
publicvoidprocess(){
A"
((A)newB()).process();
Exception"
classBextendsA{
publicvoidprocess()throwsRuntimeException{
super.process();
if(true)
thrownewRuntimeException();
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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 基础 试题