Java基础练习题 附答案(8)

2018-12-11 22:49

E.setBackground( Color c )

12)以下类中,哪个类的子类不能直接创建实例?

A.Panel B.Dialog C.Container D.Frame 十二、异常处理

1)以下程序发生什么异常? class A { int x;

public static void main { A x;

System.out.println(x.x); } }

A. IOException B. InterruptException C. NullPointerException D. DataFormatException 2)设有如下方法: public void test() { try { oneMethod();

System.out.println(\ } catch (ArrayIndexOutOfBoundsException e) { System.out.println(\ } catch(Exception e) {

System.out.println(\ } finally {

System.out.println(\ } }

如果oneMethod正常运行,则输出结果中有哪些? A. condition 1 B. condition 2 C. condition 3 D. finally

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定义如下: 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(\ 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{

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 ) D. FileOutputStream()


Java基础练习题 附答案(8).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:吉林大学计算机导论复习重点

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: