Java基础面试题

上传人:大米 文档编号:508418695 上传时间:2022-08-31 格式:DOC 页数:12 大小:34.50KB
返回 下载 相关 举报
Java基础面试题_第1页
第1页 / 共12页
Java基础面试题_第2页
第2页 / 共12页
Java基础面试题_第3页
第3页 / 共12页
Java基础面试题_第4页
第4页 / 共12页
Java基础面试题_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《Java基础面试题》由会员分享,可在线阅读,更多相关《Java基础面试题(12页珍藏版)》请在金锄头文库上搜索。

1、精选优质文档-倾情为你奉上1.下面能够得到文件“file.txt”的父路径的是:A.String name= File.getParentName(“file.txt”); B.String name= (new File(“file.txt”).getParent();C.String name = (new File(“file.txt”).getParentName();D.String name= (new File(“file.txt”).getParentFile(); 2.在Java中,要创建一个新目录,要使用的类的实例是:A.FileB.FileOutputStreanC.Pr

2、intWriterD.Dir3.题目代码的功能为:在d:创建一个文件“test.txt”,并向文件写入“HelloWorld”,然后删除文件。 public static void main(String args) File file = new File(d:, file.txt); try catch (Exception e) e.printStackTrace(); A. BufferedWriter bw = new BufferedWriter(new FileWriter(file); bw.write(HelloWorld); bw.close(); if (file.exi

3、sts() file.delete(); B. BufferedWriter bw = new BufferedWriter(new FileWriter(file); bw.write(HelloWorld); bw.close(); if (file.exists() file.deleteFile(); C.BufferedWriter bw = new BufferedWriter(file); bw.write(HelloWorld); bw.close(); if (file.exists() file.delete(); D. BufferedWriter bw = new Bu

4、fferedWriter(file); bw.write(HelloWorld); bw.close(); if (file.exists() file.deleteFile(); 4.题目代码功能为:打印扩展名为txt的文件public static void main(String args) String dir=d:/javalesson; File currDir=new File(dir); FilenameFilter filter=new JavaFilter(); String javaFiles=currDir.list(filter); for(int i=0;ijava

5、Files.length;i+) System.out.println(javaFilesi); 代码中JavaFilter类的代码为:A.public class JavaFilter implements FilenameFilter public void accept(File dir, String name) return name.endsWith(.txt); B.public class JavaFilter implements FilenameFilter public boolean accept(File dir, String name) return name.e

6、ndsWith(.txt); C.public class JavaFilter extends FilenameFilter public boolean accept(File dir, String name) return name.endsWith(.txt); D. public class JavaFilter extends FilenameFilter public void accept(File dir, String name) return name.endsWith(.txt); 5. 下列关于序列化和反序列化描述正确的是A.序列化是将数据转换为 n个byte序列的

7、过程B.反序列化是将n个 byte 转换为一个数据的过程C.将类型int 转换为4 byte是反序列化过程D.将8个字节转换为long类型的数据是序列化过程6.请看下列代码:interface Foo class Alpha implements Foo class Beta extends Alpha public class Delta extends Beta public static void main(String args) Beta x = new Beta(); 在处,填入下列代码,运行时能引起java.lang.ClassCastException异常的是:A. Alpha

8、 a = x;B. Foo f= (Delta)x;C. Foo f= (Alpha)x;D. Beta b = (Beta)(Alpha)x;7.请看下列代码:1:public class Foo 2: public static void main(String args) 3: try 4: A a = new A();5: a.method1();6: catch (Exception e) 7: System.out.print(an error occurred);8: 9: 10:1:class A 2: public void method1() 3: B b = new B(

9、);4: b.method2();5: System.out.println(method one);6: 7:1:class B 2: public void method2() 3: C c = new C();4: c.method3();5: System.out.println(method two);6: 7:1:class C 2: public void method3() 3: System.out.println(method three);4: throw new NullPointerException();5: 6:关于上述代码说法正确的是:A.Foo类的第7行将被执

10、行B.A类的第5行将被执行C.B类的第5行将被执行D.C类的第3行将被执行8.请看下列代码:public class A public String sayHello(String name) throws TestException if (name = null) throw new TestException(); return Hello + name; public static void main(String args) throws TestException A a=new A(); System.out.println(a.sayHello(null); class Tes

11、tException extends Exception 关于上述代码说法正确的是:A.A类编译失败B.代码System.out.println(a.sayHello(John);行,会抛出未检查异常TestExceptionC.代码 A a=new A();行,会抛出未检查异常TestExceptionD.代码System.out.println(a.sayHello(John);行,会抛出已检查异常TestException9.请看下列代码:1. / some code here2. try 3. / some code here4. catch (SomeException se) 5.

12、 / some code here6. finally 7. / some code here8. 下面哪三种情况能使第7行的代码执行:A.第3行抛出异常B.第1行抛出异常C.第5行抛出异常D.第3行代码成功执行10.以下说法错误的是:A.try catch . catch,多个catch时,后一个catch捕获类型一定是前一个的父类B.try.finally 可以组合使用C.throw抛出一些异常,程序不进行处理,程序编译也无错误D.throws 一定是写在方法后面11.下列代码运行的结果是:public class A public void process() System.out.pr

13、int(A ); public static void main(String args) try (A) new B().process(); catch (Exception e) System.out.print(Exception); class B extends A public void process() throws RuntimeException super.process(); if (true) throw new RuntimeException(); System.out.print(B ); A.ExceptionB.A ExceptionC.A Exception BD.A B Exception12.下列代码实现的功能是: FileOutputStream fos = new FileOutputStream(system.txt,true); PrintStream ps = new PrintStream(fos); System.setOut(ps);System.out.println(writer); A.向控制台打印“writer”,可以实现追加

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 教学/培训

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号