java复习题及答案 下载本文

内容发布更新时间 : 2024/5/8 11:10:17星期一 下面是文章的全部内容请认真阅读。

一、单项选择题

1.下面哪些是java语言中的关键字?

A.sizeof B.abstract C.NULL D.Native 2.下面语句哪个是正确的? A.char='abc'; B.long l=oxfff; C.float f=0.23; D.double=0.7E-3;

3.以下程序测试String 类的各种构造方法,试选出其运行效果。

class STR{

public static void main(String args[]){ String s1=new String();

String s2=new String(\ char chars[]={'a',' ','s','t','r','i','n','g'}; String s3=new String(chars); String s4=new String(chars,2,6); byte bytes[]={0,1,2,3,4,5,6,7,8,9}; StringBuffer sb=new StringBuffer(s3); String s5=new String(sb);

System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ } }

A.The String No.1 is The String No.2 is String 2 The String No.3 is a string The String No.4 is string The String No.5 is a string B.The String No.1 is

The String No.2 is String 2 The String No.3 is a string

The String No.4 is tring The String No.5 is a string C.The String No.1 is

The String No.2 is String 2 The String No.3 is a string The String No.4 is strin The String No.5 is a string D.以上都不对

4.下面语句段的输出结果是什么? int i = 9; switch (i) { default:

System.out.println(\ case 0:

System.out.println(\ break; case 1:

System.out.println(\ case 2:

System.out.println(\A.default B.default, zero C.error default clause not defined D.no output displayed 5.有关类Demo,哪句描述是正确的? public class Demo extends Base{ private int count; public Demo(){

System.out.println(\ }

protected void addOne() {count++; } }

A.当创建一个Demo类的实例对象时,count的值为0。 B.当创建一个Demo类的实例对象时,count的值是不确定的。

C.超类对象中可以包含改变count 值的方法。 D.Demo的子类对象可以访问count。

6.当编译和运行下列程序段时,会发生什么? class Base {}

class Sub extends Base {} class Sub2 extends Base {} public class CEx{

public static void main(String argv[]){ Base b = new Base(); Sub s = (Sub) b; } }

A.通过编译和并正常运行。 B.编译时出现例外。

C.编译通过,运行时出现例外。

7.如果任何包中的子类都能访问超类中的成员,那么应使用哪个限定词?

A.public B.private C.protected D.8.下面的哪个选项是正确的? class ExSuper{ String name;

String nick_name;

public ExSuper(String s,String t){ name = s;

nick_name = t; }

public String toString(){ return name; } }

public class Example extends ExSuper{ public Example(String s,String t){ super(s,t);

transient

}

public String toString(){

return name +\ }

public static void main(String args[]){

ExSuper a = new ExSuper(\ ExSuper b = new Example(\ System.out.println(\ System.out.println(\

} }

A.编译时会出现例外。 B.运行结果为:

a is First b is second C.运行结果为:

a is First

b is Secong a.k.a 2nd D.运行结果为:

a is First a.k.a 1nd b is Second a.k.a 2nd 9.运行下列程序的结果是哪个? abstract class MineBase { abstract void amethod(); static int i; }

public class Mine extends MineBase {

public static void main(String argv[]){ int[] ar = new int[5];

for(i = 0;i < ar.length;i++) System.out.println(ar[i]); } }

A.打印5个0。

B.编译出错,数组ar[]必须初始化。 C.编译出错, Mine应声明为abstract。 D.出现IndexOutOfBoundes的例外。 10.请问所有的例外类皆继承哪一个类? A.java.io.Exception B.java.lang.Throwable C.java.lang.Exception D.java.lang.Error 11.下面程序段的执行结果是什么? public class Foo{

public static void main(String[] args){ try{

return;}

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

A.程序正常运行,但不输出任何结果。 B.程序正常运行,并输出 \。

C.编译能通过,但运行时会出现一个例外。 D.因为没有catch语句块,所以不能通过编译。 12.编译Java Application 源程序文件产生的字节码文件的扩展名为( )。 A.java B.class C.html D.exe 13.下列哪个是合法的Java标识符( )? A.&2 C._2#

B.123.9

D.public

14.设有下面两个类的定义:

class Person { long id; //身份证号

String name; // 姓名 }

class Student extends Person { int score; // 入学总分