第一范文网 - 专业文章范例文档资料分享平台

Java基础练习题附答案

来源:用户分享 时间:2025/5/23 18:42:50 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

word格式

3) 设有如下代码: public void fun () { int i; try {

i=System.in.read ();

System.out.println(\ } catch (IOException e) {

System.out.println(\ } finally {

System.out.println(\ }

System.out.println(\}

如果有一个IOException发生, 则输出有哪些? A. Location 1 B. Location 2 C. Location 3 D. Location 4 4) 设有如下代码:

1 String s = null;

2 if ( s != null & s.length() > 0)

3 System.out.println(\ 4 if ( s != null && s.length() > 0)

5 System.out.println(\ 6 if ( s != null || s.length() > 0)

7 System.out.println(\ 8 if ( s != null | s.length() > 0)

9 System.out.println(\以下行中哪些会产生空指针异常。 A. 2,4 B. 6,8 C. 2,4,6,8 D. 2,6,8

5) 类Test1、Test2定义如下:

.. ..

word格式

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{ } 6)设有如下代码: try {

tryThis(); return;

} catch (IOException x1) {

System.out.println(\ return;

} catch (Exception x2) {

System.out.println(\ return; } finally {

System.out.println(\ }

如果tryThis() 抛出 NumberFormatException,则输出结果是? A. 无输出

B. \后跟 \C. \后跟 \D. \E. \

十三、流式输入输出与文件处理

1)以下哪个是RandomAccessFile文件的构造方法: A.RandomAccessFile(\B.RandomAccessFile(\

.. ..

word格式

C.RandomAccessFile(\D.RandomAccessFile(\2)设有如下代码: import java.io.*; public class Th{

public static void main(String argv[]){ Th t = new Th(); t.amethod(); }

public void amethod(){ try{ ioCall();

}catch(IOException ioe){} } }

以下哪个最有可能是ioCall方法的方法体? A. public void ioCall () throws IOException{

DataInputStream din = new DataInputStream(System.in); din.readChar(); }

B. public void ioCall () throw IOException{

DataInputStream din = new DataInputStream(System.in); din.readChar(); }

C. public void ioCall (){

DataInputStream din = new DataInputStream(System.in); din.readChar(); }

D. public void ioCall throws IOException(){

DataInputStream din = new DataInputStream(System.in); din.readChar(); }

3)当前目录不存在名为Hello.txt的文件,执行下面代码的输出结果为? import java.io.*; public class Mine{

.. ..

word格式

public static void main(String argv[]){ Mine m=new Mine( );

System.out.println(m.amethod()); }

public int amethod(){ try{

FileInputStream file=new FileInputStream(\ }

catch(FileNotFoundException e){

System.out.print(\ return -1; }

catch(IOException e){

System.out.print(\ } return 0; } }

A. No such file found B. No such file found-1

C. No such file foundDoing finally-1 D. 0

4) 使用哪个类可创建目录?

A. File B. DataOutput C. Directory D. FileDescriptor E. FileOutputStream

5) 假设raf是一个随机访问文件,以下语句的编译和运行结果为?raf.seek( raf.length() ); A.代码不能编译. B.会出现IOException

C.文件指针将定位到文件的最后一个字符之前 D.文件指针将定位到文件的最后一个字符

6)以下哪些是FileOutputStream 构造方法的合法形式? A. FileOutputStream( FileDescriptor fd ) B. FileOutputStream( String n, boolean a ) C. FileOutputStream( boolean a )

.. ..

搜索更多关于: Java基础练习题附答案 的文档
Java基础练习题附答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c6w3fx7spq025ui718xfz9x6b742s6901dui_10.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top