当前位置:文档之家› Java 输入输出(含部分答案)

Java 输入输出(含部分答案)

Java输入输出知识点:1、文件和流的操作,理解字节流和字符流的概念2、异常处理的概念,自定义异常类一、选择题1、如果一个程序段中有多个catch,则程序会按如下哪种情况执行( )A)找到合适的例外类型后继续执行后面的catchB)找到每个符合条件的catch都执行一次C)找到合适的例外类型后就不再执行后面的catchD)对每个catch都执行一次2、程序员将可能发生异常的代码放在()块中,后面紧跟着一个或多个()块。

A) catch、try B) try、catchC) try、exception D) exception、try3、在Java语言中,在程序运行时会自动检查数组的下标是否越界,如果越界,会抛掷下面的异常( )A) SQLException B) IOExceptionC) ArrayIndexOutOfBoundsExcetion D) SecurityManager4、在Java中,关于捕获异常的语法try-catch-finally的下列描述哪些正确( )A) try-catch必须配对使用B) try可以单独使用C) try-finally必须配对使用D) 在try-catch后如果定义了finally,则finally肯定会执行5、给定下面的代码片断:public class Animal{public void Cat(){try{Method();}catch(ArrayIndexOutBoundsException e){"Exception1");}catch(Exception e){"Exception2");}finally{"Hello World!!");}}public void Method(){}public static void main(String[] args){=new Animal ();Ani. Cat ();}}如果函数method正常运行并返回,会显示下面的哪些信息( )A) Hello World B) Exception1C) Exception2 D) Hello World!!6、如果下列的方法能够正常运行,在控制台上将显示什么( )public void example(){try{unsafe();"Test1");}catch(SafeException e){"Test 2");}finally{"Test 3");}"Test 4");}A) Test 1 B) Test 2C) Test 3 D) Test 47、以下哪一项不是File类的功能: ( )A) 创建文件B) 创建目录C) 删除文件D) 拷贝文件2、下面哪个不是InputStream类中的方法: ( )A) int read(byte[]) B) void flush()C) void close() D) int available()8、构造BufferedInputStream的合适参数是哪个A) BufferedInputStream B) BufferedOutputStreamC) FileInputStream D) FileOuterStreamE) File9、要从文件" "文件中读出第10个字节到变量C中,下列哪个方法适合( )A) FileInputStream in=new FileInputStream("");(9); int c=();B) FileInputStream in=new FileInputStream(""); (10); int c=();C) FileInputStream in=new FileInputStream(""); int c=();D) RandomAccessFile in=new RandomAccessFile(""); (9);int c=();10、以下程序发生什么异常class A {int x;public static void main {A x;}}A.IOExceptionB. InterruptExceptionC. NullPointerExceptionD. DataFormatException11、设有如下方法:public void test() {try {oneMethod();"condition 1");} catch (ArrayIndexOutOfBoundsException e) {"condition 2");} catch(Exception e) {"condition 3");} finally {"finally");}}如果oneMethod正常运行,则输出结果中有哪些A. condition 1B. condition 2C. condition 3D. finally12、设有如下代码:public void fun () {int i;try{i= ();"Location 1");} catch (IOException e) {"Location 2");} finally {"Location 3");}"Location 4");}如果有一个IOException发生, 则输出有哪些A. Location 1B. Location 2C. Location 3D. Location 413、设有如下代码:1 String s = null;2 if ( s != null & () > 0)3 "s != null & () > 0");4 if ( s != null && () > 0)5 "s != null & () > 0");6 if ( s != null || () > 0)7 "s != null & () > 0");8 if ( s != null | () > 0)9 "s != null | () > 0");以下行中哪些会产生空指针异常。

A. 2,4B. 6,8C. 2,4,6,8D. 2,6,814、类Test1、Test2定义如下:1.public class Test1 {2.public float aMethod(float a,float b)throws IOException { 3.}4.}5.public class Test2 extends Test1{6.7.}将以下哪种方法插入行6是不合法的。

A、float aMethod(float a,float b){ }B、public int aMethod(int a,int b)throws Exception{ }C、public float aMethod(float p,float q){ }D、public int aMethod(int a,int b)throws IOException{ }15、设有如下代码:try {tryThis();return;} catch (IOException x1) {"exception 1");return;} catch (Exception x2) {"exception 2");return;} finally {"finally");}如果tryThis() 抛出NumberFormatException,则输出结果是A. 无输出B. "exception 1", 后跟"finally"C. "exception 2", 后跟"finally"D. "exception 1"E. "exception 2"16、以下哪个是RandomAccessFile文件的构造方法: A.RandomAccessFile("data", "r");B.RandomAccessFile("r", "data");C.RandomAccessFile("data", "read"); D.RandomAccessFile("read", "data");17、设有如下代码:import .*;public class Th{public static void main(String argv[]){Th t = new Th();();}public void amethod(){try{ioCall();}catch(IOException ioe){}}}以下哪个最有可能是ioCall方法的方法体A.public void ioCall () throws IOException{DataInputStream din = new DataInputStream;();}B.public void ioCall () throw IOException{DataInputStream din = new DataInputStream;();}C.public void ioCall (){DataInputStream din = new DataInputStream;();}D.public void ioCall throws IOException(){DataInputStream din = new DataInputStream;();}18、当前目录不存在名为的文件,执行下面代码的输出结果为import .*;public class Mine{public static void main(String argv[]){Mine m=new Mine( );}public int amethod(){try{FileInputStream file=new FileInputStream("");}catch(FileNotFoundException e){"No such file found");return -1;}catch(IOException e){"Doing finally");}return 0;}}A. No such file foundB. No such file found-1C. No such file foundDoing finally-1D. 019、使用哪个类可创建目录A.File B.DataOutput C.Directory D.FileDescriptor E. FileOutputStream20、假设raf是一个随机访问文件,以下语句的编译和运行结果为( () ); A.代码不能编译.B.会出现IOExceptionC.文件指针将定位到文件的最后一个字符之前D.文件指针将定位到文件的最后一个字符21、以下哪些是FileOutputStream 构造方法的合法形式A.FileOutputStream( FileDescriptor fd )B.FileOutputStream( String n, boolean a )C.FileOutputStream( boolean a )D.FileOutputStream()E.FileOutputStream( File f )22、以下哪个能编译通过A.File f = new File("/","");B. DataInputStream d = new DataInputStream;C. OutputStreamWriter o = new OutputStreamWriter;D. RandomAccessFile r = new RandomAccessFile("OutFile");23、以下程序的调试结果为:import .*;class Base{public void amethod()throws FileNotFoundException{}}public class ExcepDemo extends Base{public static void main(String argv[]){ExcepDemo e = new ExcepDemo();}public void amethod(){}protected ExcepDemo(){try{DataInputStream din = new DataInputStream;"Pausing");();"Continuing");();}catch(IOException ioe) { }}}A. 由于构造方法为protected导致编译出错B. 由于amethod方法未声明异常导致编译出错C. 由于amethod方法未声明异常导致运行错误D. 输出显示"Pausing",击键后显示"Continuing"24、下列描述中不属于Java异常处理机制优点的一项是( D )。

相关主题