Java基础面试题_第1页
Java基础面试题_第2页
Java基础面试题_第3页
Java基础面试题_第4页
Java基础面试题_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

精品文档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.PrintWriterD.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.exists() 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 BufferedWriter(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;ijavaFiles.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.endsWith(.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序列的过程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 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();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行将被执行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 TestException 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. / 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.print(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 cess(); 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”,可以实现追加打印B.向控制台打印“writer”,但是不可以实现追加打印C.向文件system.txt写“writer”,但是不可以实现追加写D.向文件system.txt写“writer”,可以实现追加写13.在Java中,下面的代码会出现编译错误的是:A.File f = new File(/,autoexec.bat);B.DataInputStream din = new DataInputStream(new FileInputStream(autoexec.bat);C.InputStreamReader in = new InputStreamReader(System.in);D.OutputStreamWriter out = new OutputStreamWriter(System.in); 14.java.io.BufferedWriter 和java.io.FileWriter相比, java.io.FileWriter没有但是java.io.BufferedWriter有的方法是:A.关闭流的方法B.刷新流的缓冲的方法C.写入流的方法D.写入一个行分隔符15. 给定一个Java程序的main方法的代码片段如下:假如d 盘下不存在abc.txt文件,现运行该程序,下面说法正确的是( )try PrintWriter out=new PrintWriter(new FileOutputStream(“d:/abc.txt”) ; String name=”tarena”; out.print(name) ; out.close( ) ;catch(Execption e) System.out.println(“文件没有发现!“) ;A.将在控制台上打印:“文件没有发现!”B.正常运行,但没有生成文件abc.txtC.运行后生成abc.txt ,但该文件中无内容D.运行后生成abc.txt,该文件内容为:tarena16. 关于java.io.Serializable接口说法正确的是:A.java.io.Serializable中有一个serialID属性,但是没有方法B.类通过实现java.io.Serializable 接口以启用其序列化功能C.java.io.Serializable中有一个run方法,但是没属性D.java.io.Serializable接口没有方法或属性,仅用于标识可序列化的语义。17.关于线程的设计,下列描述正确的是:A.线程对象必须实现Runnable接口B.启动一个线程直接调用线程对象的run()方法C.Java提供对多线程同步提供语言级的支持D. 一个线程可以包含多个进程18.下列代码编译和运行的结果是: public static void main(String args) Runnable r = new Runnable() public void run() System.out.print(Cat); ; Thread t = new Thread(r) public void run() System.out.print(Dog); ; t.start(); A.CatB.DogC.运行无输出D.编译失败19.下面能使线程处于阻塞状态的是:A.sleep();B.notify();C.synchronized(Object obj)D.wait();20.下列代码编译和运行的结果是:public class TestOne public static void main(String args) throws Exception Thread.sleep(3000); System.out.println(sleep); A.编译错误B.抛出运行时异常C.输出:sleepD.代码正常运行,但是无输出21.现有一个线程dt,把dt线程设置为守护线程的方式正确的是:A.Thread.setDaemon(true);B.dt.daemon(true);C.Thread.daemon(true);D.dt.setDaemon(true);22.请看下列代码:class ThreadDemo implements Runnable int age=0; public synchron

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论