JAVA程序设计(华东交通大学)智慧树知到网课章节测试答案

第一章 单元测试
1、单选题:编译和运行以下代码的结果为:  public class MyMain{         public static void main(String argv){          System.out.println(“Hello cruel world”);       } }
A:编译错误
B:运行输出 ‘Hello cruel world’
C:编译无错,但运行时指示没有定义构造方法
D:编译无错,但运行时指示找不到main方法
答案: 【编译无错,但运行时指示找不到main方法】
2、单选题:以下哪个是Java应用程序入口的main方法头?
A:public static void main(String a[])
B:public static int main(char args[])
C:public static void main(String argv)
D:public static void MAIN(String args[])
答案: 【public static void main(String a[]) 】
3、单选题:编译Java源程序文件将产生相应的字节码文件,字节码文件的扩展名为?
A:exe
B:java
C:class
D:html
答案: 【class】
4、多选题:main方法是Java  Application程序执行的入口点,关于main方法的方法头合法的有?
A:public static void main()
B:public static void main(String[ ] args)
C:public static void main(String arg[ ])
D:public static int main(String[ ] arg)
答案: 【public static void main(String[ ] args);public static void main(String arg[ ])】
5、判断题:每个源程序文件中只能定义一个类。
A:对
B:错
答案: 【错】

第二章 单元测试
1、单选题:在Java中,十进制数16的十六进制表示格式是?
A:0xA
B:0x10
C:016
D:0x16
答案: 【0x10】
2、单选题:要产生[10,100]之间的随机整数使用哪个表达式?
A:(int)(Math.random()*100)
B:10+(int)Math.random()*90
C:10+(int)Math.random()*91
D:10+(int)(Math.random()*91)
答案: 【10+(int)(Math.random()*91)】
3、单选题:下列符号中不能作为Java标识符的是?
A:abc
B:$str1
C: _pore
D:45six
答案: 【45six】
4、单选题:下面各项中定义变量及赋值不正确的是?
A:double d = 45.0;
B:char c = 65;
C:float f = 45.0;
D:int i = 32;
答案: 【float f = 45.0;】
5、单选题:执行以下代码段后, x, a,和 b的值为?  int x, a = 6, b = 7;  
x = a++ + b++;
A:x= 13, a=6, b=7
B:x= 15, a=6, b=7
C:x= 15, a=7, b=8
D:x= 13, a=7, b=8
答案: 【x= 13, a=7, b=8】
6、单选题:下列哪个不是Java的保留字?
A:extends
B:cin
C:class
D:float
答案: 【cin】
7、多选题:哪些赋值是合法的?
A: float f = -412;
B:long test = 012;
C:int other = (int)true;
D:double d = 0x12345678;
答案: 【 float f = -412;;long test = 012; ;double d = 0x12345678; 】
8、多选题:下列代码中,将引入编译错误的行是1 public class Exercise{2  public static void main(String args[]){3     float f = 0.0 ;4     f = f + 1.0 ;5  }6 }
A:第3行
B:第6行
C:第4行
D:第2行
答案: 【第3行;第4行】
9、多选题:下列哪些是合法标识符?
A:$persons
B:*point
C:this
D:TwoUsers
答案: 【$persons ;TwoUsers】
10、多选题:下列哪些是java中有效的整数表示形式?
A:22H
B:0x22
C:022
D:22
答案: 【0x22;022;22】

第三章 单元测试
1、单选题:如何更改break语句使退出inner和middle循环,继续外循环的下一轮? outer: for (int x = 0; x < 3; x++) { middle: for (int y = 0; y < 3; y++) { inner: for (int z = 0; z < 3; z++) {         if (arr(x, y, z) == targetValue)            break;       }   }}
A: continue;
B:break outer;
C:break middle;
D:break inner;
答案: 【break middle; 】
2、单选题:以下程序的输出结果为?public class Test {   public static void main(String args[]) {     for ( int k = 0; k < 3; k++)          System.out.print(“k”);   } }
A:kkk
B:k
C:012
D:0123
答案: 【kkk】
3、单选题:以下代码的调试结果为?1:    public class Q102:    {3:      public static void main(String[] args)4:      {5:          int i = 10;6:          int j = 10;7:          boolean b = false;8:          9:          if( b = i == j)10:            System.out.println(“True”);11:         else12:            System.out.println(“False”);13:       }14:    }
A:在第9行出现运行异常
B:输出 :True
C:在第9行出现编译错误
D:输出 :False
答案: 【输出 :True】
4、单选题:以下代码的调试结果为?public class test {  public static void main(String args[]) {     int i = 1;    do {        i–;    } while (i > 2);    System.out.println(i);  }}
A:1
B:2
C:0
D:-1
答案: 【0】
5、单选题:下面的代码段执行之后count的值是什么?    int count = 0;    for (int i = 1; i < 4; i++) {         count += i;    }    System.out.println(count);
A:1
B:6
C:4
D:10
答案: 【6】
6、单选题:以下程序的运行结果为:     1. public class Conditional {     2.    public static void main(String args [] )  {     3.      int x = 4;     4.      System.out.println( “value is ” +     5.         ((x > 4)  ? 99.99 : 9));     6.    }     7.  }
A:输出: value is 9.0
B:输出: value is 9
C:在第5行出现编译错误
D:输出:value is 99.99
答案: 【输出: value is 9.0】
7、单选题:下列程序的运行结果?public class Test {    public static void main(String a[]) {        int x=3,y=4,z=5;        if (x>3) {          if (y<2)            System.out.println(“show one”);          else            System.out.println(“show two”);         }         else {           if (z>4)            System.out.println(“show three”);          else            System.out.println(“show four”);         }    }}
A: show three
B:show four
C:show one
D:show two
答案: 【 show three 】
8、单选题:以下程序调试结果 public class test {   public static void main(String args[]) {       int i=1, j=3;      while (j>0) {         j–;         i++;               }       System.out.println(i);   }}
A:0
B:2
C:3
D:4
答案: 【4】
9、多选题:在switch(expression)语句中,expression的数据类型不能是?
A:boolean
B:double
C:char
D:byte
答案: 【boolean;double】
10、多选题:假设a是int类型变量,并初始化为1,则下列哪个为合法的条件语句?
A:if (a=2) { }
B:if (a) { }
C: if (true) { }
D: if (a<3) { }
答案: 【 if (true) { }; if (a<3) { } 】

第四章 单元测试
1、单选题:以下程序运行时输入:java Cycle hello two me 2
public class Cycle{
public static void main(String args[]){
System.out.println(args[1]);
}
}
则运行结果为?
A:hello
B:2
C:me
D:two
答案: 【two】
2、单选题:public class test {
  public static void main(String args[]) {
    int m=0;
    for ( int k=0;k<2;k++)
      method(m++);
    System.out.println(m);
  }
  public static void method(int m) {
    System.out.print(m);
  }
A:123
B:012
C:111
D:000
答案: 【012】
3、单选题:以下程序运行结果为:public class Q {
   public static void main(String argv[]) {
      int anar[]= new int[5];
      System.out.println(anar[0]);
   }}
A:”null”
B:0
C:出错: anar在未初始化前被引用
D:5
答案: 【0】
4、单选题:下列程序的运行结果是:
public class Test {
public static void main(String args[]) {
int m[]={1,2,3,4,5,6,7,8};
int sum = 0;
for (int i=0;i<8;i++){
sum = sum + m[i];
if (i==3) break;
}
System.out.println(sum);
}
}
A:36
B:6
C:3
D:10
答案: 【10】
5、单选题:下面定义和给数组初始化正确的是:A:String temp = {”a”, ”b”, ”c”};
B:String temp [] = { ‘j ‘, ‘ b’ ,’c’};
C:String temp [] = new String {”j” ”a” ”z”};
D:String temp [] = {”a”, ”b”, ”c”};
答案: 【String temp [] = {”a”, ”b”, ”c”};】
6、单选题:在注释//Start For loop 处要插入哪段代码可以实现根据变量i的值定位访问数组ia[]的所有元素。 public class Lin{    public void amethod(){        int ia[] = new int[4];         //Start For loop               {        ia[i]=i;                  System.out.println(ia[i]);           }       }  }
A:for (int i=0; i< ia.length;i++)
B:for (int i=0; i< ia.length(); i++)
C:for (int i=0; i< ia.length-1; i++)
D:for (int i=0; i < ia.length() -1; i++)
答案: 【for (int i=0; i< ia.length;i++)】
7、单选题:设有如下程序,其调试结果为:class Q2 {       public static void main(String[] args) {         int[] seeds = {1,2,3,4,6,8};         int n= seeds.length;        for (int i = 0; i < 3; i++)           for (int k = 0; k< n-1; k++)            seeds[k]= seeds[k+1];         for (int i = 0; i <n; i++)            System.out.print(“t”+seeds[i]);        }}
A:输出: 4 6 8 8 8 8
B:输出: 1 2 3 4 6 8
C:输出: 2 3 4 6 8 8
D:输出: 2 3 4 6 6 8
答案: 【输出: 4 6 8 8 8 8】
8、多选题:下列选项能正确定义一个整形数组的是:A:int scores[];
B:int scores={0,0,0,0};
C:int[] scores;
D:int scores=new int[10];
答案: 【int scores[];;int[] scores;】
9、多选题:设有如下代码: int[] x = new int[25]; 执行后,以下哪个说法正确?
A:x[25] 为 0.
B:x[24] 为 0
C:x.length 为 25.
D:x[0] 为null.
答案: 【x[24] 为 0;x.length 为 25.】

第五章 单元测试
1、单选题:关于以下程序的说明,正确的是(        )
1.  class   StaticStuff2. { 3.     static  int  x=10;4.     static  { x+=5;}5.     public  static  void  main(String  args[ ])6.     {7.        System.out.println(“x=” + x);8.      }9.     static  { x/=3;}10.   }
A:编译通过,执行结果为:x=5
B:编译通过,执行结果为:x=3
C:9行不能通过编译,因为只能有一个静态初始化器
D:4行与9行不能通过编译,因为缺少方法名和返回类型
答案: 【编译通过,执行结果为:x=5】
2、单选题:以下程序编译和运行会发生什么
public class Q8   {
int i = 20;
static { int i = 10;  }
public static void main(String[] args)  {
Q8 a = new Q8();
System.out.println(a.i);
}
}
A:编译错误,静态初始化只能用于初始化目的
B:编译错误,变量 ‘i’ 定义2次.
C:输出 20.
D:输出 10.
答案: 【输出 20.】
3、单选题:给出如下类定义: public class test {    
 test(int k) { } }如果要创建一个该类的对象,正确的语句是:A:test obj1 = new test(‘5 ‘);
B:test obj1 = new test(5);
C:test obj1 = new test(3.4);
D:test obj1 = new test();
答案: 【test obj1 = new test(5);】
4、单选题:有如下代码:public class Person { …  } 下列哪个符合该类的构造方法定义
A:public static void Person() {…}
B:public Person() {…}
C:public int Person() {…}
D:public void Person() {…}
答案: 【public Person() {…}】
5、单选题:以下代码的输出结果?
public class Test{
static int x=5;
public static void main(String argv[]){
change(x);
x++;
System.out.println(x);
}
static void change(int m){
m+=2;
}}
A:8
B:7
C:5
D:6
答案: 【6】
6、单选题:设有如下程序:public class Test5 {    public static void main (String args []) {     /* This is the start of a comment            if (true) {                  Test5 = new test5();             System.out.println(“Done the test”);       }         /* This is another comment */          System.out.println (“The end”);   }}结果为?
A:程序输出”Done the test”和 “The end”
B:程序编译错误.
C: 程序输出”The end”
D:输出 “Done the test”.
答案: 【 程序输出”The end”】
7、多选题:给出下面的不完整的类代码:class Person {
String name, department;
int age;
public Person(String n){ name = n; }
public Person(String n, int a){ name = n; age = a; }
public Person(String n, String d, int a) {
// doing the same as two arguments version of constructor
// including assignment name=n,age=a
department = d;
}
}
下面的哪些表达式可以加到构造方法中的”doing the same as…”处?
A:name=n;age=a;
B:Person(n,a);
C:this(n,a);
D:this(name,age);
答案: 【name=n;age=a;;this(n,a);】
8、多选题:考虑如下类:public class Test {         int j,k;             public Test(int j ) {             this(j,0);       }       public Test(int j, int k)  {         this.j=j;              this.k=k;       }  }
以下哪些可正确创建Test对象?
A:Test t = new Test(1, 2, 3);
B:Test t = new Test(1, 2);
C:Test t = new Test();
D:Test t = new Test(1);
答案: 【Test t = new Test(1, 2);;Test t = new Test(1);】

第六章 单元测试
1、单选题:在Java中,如下的修饰符不是访问控制修饰符
A:private
B:static
C:public
D:protected
答案: 【static】
2、单选题:类Test1定义如下:1.public  class  Test1{2.     public  float  aMethod(float  a,float  b){   }3.        4.}
将以下哪种方法插入行3是不合法的。
A:public float aMethod(float a, float b,float c){ }
B:private float aMethod(int a,int b,int c){ }
C:public int aMethod(int a, int b){ }
D:public float aMethod(float c,float d){ }
答案: 【public float aMethod(float c,float d){ }】
3、单选题:以下代码调试结果
class Base {}
class Sub extends Base {}
public class CEx{
public static void main(String argv[]){
Base b = new Base();
Sub s = (Sub) b;
}
}
A:运行异常
B:编译异常
C:调试通过
D:运行没输出
答案: 【运行异常】
4、单选题:如何定义一个不能有子类的类Key?
A:native class Key { }
B:class Key { }
C:final class Key { }
D:abstract final class Key { }
答案: 【final class Key { } 】
5、单选题:class Person {
private int a;
public int change(int m){ return m; }
}
public class Teacher extends Person {
public int b;
public static void main(String arg[]){
Person p = new Person();
Teacher t = new Teacher();
int i;
// point x
}
}
在 // point x安排哪个语句合法?
A: i = p.change(30);
B:i = p.a;
C:i = m;
D:i = b;
答案: 【 i = p.change(30);】
6、单选题:如何能使程序调用Base类的构造方法输出”base constructor”; class Base{   Base(int i){      System.out.println(“base constructor”);   }   Base(){  }}public class Sup extends Base{   public static void main(String argv[]){       Sup s= new Sup();       //One    }    Sup() {      //Two    }   public void derived() {      //Three   }}
A: 在//One行之后放置super(10);
B:在//Three行之后放置super(10);
C:在//One行之后放置Base(10);
D:在//Two行之后放置super(10);
答案: 【在//Two行之后放置super(10);】
7、单选题:以下程序的输出为?    1:    class MyClass    2:    {    3:        static int maxElements;    4:        5:        MyClass(int maxElements)    6:        {    7:            this.maxElements = maxElements;    8:        }    9:        10:    }    11:    12:    public class Q19    13:    {    14:        public static void main(String[] args)    15:        {    16:        17:            MyClass a = new MyClass(100);    18:            MyClass b = new MyClass(100);    19:            20:            if(a.equals(b))    21:                System.out.println(“Objects have the same values”);    22:            else    23:                System.out.println(“Objects have different values”);    24:        }    25:    }
A:输出 “Objects have different values”
B:编译通过,在运行时20行出现异常
C:输出 “Objects have the same values”.
D:在第20行出错. equals()方法未定义.
答案: 【输出 “Objects have different values”】
8、单选题:在构造方法的哪个地方可以调用父类的构造方法?
A:构造方法的第一条语句
B:任何地方
C:不能在构造方法中调用super
D:构造方法的最后一条语句
答案: 【构造方法的第一条语句】
9、单选题:定义常量时使用的关键字是
A:abstract
B:const
C: static
D:final
答案: 【final】
10、多选题:设有如下代码:class Base{}
public class MyCast extends Base{
static boolean b1=false;
static int i = -1;
static double d = 10.1;
public static void main(String argv[]){
MyCast m = new MyCast();
Base b = new Base();
//Here
}
}
则在 //Here处插入哪个代码将不出现编译和运行错误。
A:b1 =i;
B:b=m;
C:d =i;
D:m=b;
答案: 【b=m;;d =i; 】
第七章 单元测试
1、单选题:测试如下代码:  public class Ref{   public static void main(String[] args)  {     StringBuffer sbl = new StringBuffer(“Hello”);     StringBuffer sb2 = new StringBuffer(“Hello”);     boolean result = sbl.equals(sb2);     System.out.println(result);   } } 下述哪条语句正确描述了程序编译和运行的行为?
A:编译成功,输出为 true
B:编译成功,输出为 0
C:编译成功,输出为 1
D:编译成功,输出为 false
答案: 【编译成功,输出为 false】
2、单选题:String alphabet=”ABCDEFGHIJKLMNOPQ”调用alphabet.substring(6,10)返回什么子字符串?
A:FGHI
B:CDEF
C: GHIJ
D:EFGH
答案: 【 GHIJ】
3、单选题:以下程序的调试结果为?
1. public class EqualsTest{
2.   public static void main(String args[]){
3.     Long LA = new Long(7);
4.     Long LB = new Long(7);
5.     if(LA==LB) System.out.println(“Equal”);
6.     else System.out.println(“Not Equal”);
7.    }
8. }
A:编译错误
B:输出”Equal”
C: 程序在执行到第5行时出现异常
D:输出”Not Equal”
答案: 【输出”Not Equal”】
4、单选题:有如下代码:public class Test{
public static void main(String args[]) {
String  str = new String(“World”);
char  ch[] = {‘H’,’e’,’l’,’l’,’o’};
change(str,ch);
System.out.println(str + “and” + ch);
}
public static void change(String str, char ch[]) {
str = “Changed”;
ch[0] = ‘C’;
}
}
运行后输出的结果是:A:World and Hello
B:World and Cello
C:Changed and Cello
D:World and CelloChanged and Hello
答案: 【World and Cello】
5、多选题:已知代码:  String s = "story";下列语句中合法的是:A:int len = s.length;
B:String t = s.toLowerCase();
C:char c = s[1];
D:s += “books”;
答案: 【String t = s.toLowerCase();;s += “books”;】
第八章 单元测试
1、单选题:以下程序的编译和运行结果为?abstract class Base{    abstract public void myfunc();    public void another(){        System.out.println(“Another method”);    }}public class Abs extends Base{    public static void main(String argv[]){        Abs a = new Abs();        a.amethod();     }    public void myfunc(){         System.out.println(“My Func”);     }     public void amethod(){        myfunc();           }}
A:编译指示Base 类中的myfunc方法无方法体,没谁会喜欢该方法
B:编译通过,但运行时指示Base 类中无抽象方法
C:编译指示 Base 类中无抽象方法
D:输出结果为 My Func
答案: 【输出结果为 My Func】
2、单选题:以下代码的调试结果为?
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:编译错误指示: Mine 必须定义为抽象的
B:运行错误,i超出数组下标范围
C:输出5个0
D:编译错误指示: ar 未初始化就使用
答案: 【编译错误指示: Mine 必须定义为抽象的】
3、单选题:有关内嵌类以下哪个叙述为假?
A:内嵌类可以访问外部类的成员
B:方法中的内嵌类可以访问方法中定义的常量
C:内嵌类可以被定义为静态成员
D:匿名内嵌类没有对应的字节码文件
答案: 【匿名内嵌类没有对应的字节码文件】
4、单选题:以下哪个正确定义抽象类?
A:abstract class Animal {abstract void growl();}
B:class Animal { abstract void growl(); }
C:abstract Animal {abstract void growl();}
D:class abstract Animal {abstract void growl();}
答案: 【abstract class Animal {abstract void growl();}】
5、单选题:考虑如下代码,其中包括一个内嵌类:public final class Test4 {  class Inner {     void test() {       if (Test4.this.flag)        {         sample();       }     }   }  private boolean flag = false;  public void sample() {    System.out.println(“Sample”);  }  public Test4() {    (new Inner()).test();   }  public static void main(String args []) {     new Test4();  } }结果为?
A:程序编译失败
B:程序无输出,但正确终止
C:输出 “Sample”
D:程序不能终止
答案: 【程序无输出,但正确终止】
6、多选题:有关抽象类,以下哪点为真?
A:类定义包含abstract 关键字
B:不能派生子类
C:不能对该类实例化
D:所有方法均为抽象方法
答案: 【类定义包含abstract 关键字;不能对该类实例化】
7、多选题:设有类定义如下:class InOut{
String s= new String(“Between”);
public void amethod(final int iArgs){
int  iam=5;
iam++;
class Bicycle{
public void sayHello(){
//Here
}
}
}
public void another(){   int iOther; }
}
以下哪些语句可以安排在//Here处 ?
A:System.out.println(s);
B:System.out.println(iArgs);
C:System.out.println(iam);
D:System.out.println(iOther);
答案: 【System.out.println(s);;System.out.println(iArgs);】
8、多选题:在抽象类中,抽象方法定义正确的是?
A:abstract void Method();
B: public abstract void method();
C: public abstract method();
D:public abstract void method() {}
答案: 【abstract void Method(); ; public abstract void method();】
9、多选题:设有如下代码:interface IFace{ }class CFace implements IFace{ }class Base{ }public class ObRef extends Base{    public static void main(String argv[]){        ObRef obj = new ObRef();        Base b = new Base();        Object obj1 = new Object();        IFace obj2 = new CFace();         //Here    }}则在 //Here处插入哪个代码将不出现编译和运行错误。
A:obj=b;
B:obj1=obj2;
C:obj1=b;
D:b=obj;
答案: 【obj1=obj2;;obj1=b;;b=obj;】
10、多选题:下列说法正确的是?
A:一个类可以根据需要实现多个接口
B:子类继承了父类的所有方法(包括构造方法)
C:一个类定义时没指定父类,则继承Object类。
D:java中的子类只允许有一个直接父类
答案: 【一个类可以根据需要实现多个接口;一个类定义时没指定父类,则继承Object类。;java中的子类只允许有一个直接父类】

第九章 单元测试
1、单选题:自定义异常的父类是?
A:VirtualMachineError
B:Exception
C:Thread
D:Error
答案: 【Exception】
2、单选题:在命令行输入如下命令,结果为   java myprog good morningpublic class myprog{   public static void main(String argv[]) {      System.out.println(argv[2]);   } }
A: good
B:myprog
C:出现异常 “java.lang.ArrayIndexOutOfBoundsException: 2”
D:morning
答案: 【出现异常 “java.lang.ArrayIndexOutOfBoundsException: 2”】
3、单选题:假设m()方法声明抛出IO异常,哪个书写合法.
A:void m(void) throws IOException{}
B:void m() throw IOException{}
C:void m() throws IOException{}
D:void m() {} throws IOException
答案: 【void m() throws IOException{}】
4、单选题:下列关键字中用于明确抛出一个异常的是?
A: try
B: catch
C:throw
D:finally
答案: 【throw】
5、单选题:检查下面的代码: class E1 extends Exception{} class E2 extends E1{} public class Quiz6_l{   public static void f(boolean flag) throws E1,E2{      if(flag)  {        throw new E1();      }  else  {        throw new E2();      }    }   public static void main(String[] args)  {     try{       f(true);     }    catch(E2 e2)  {       System.out.println(“Caught E2”);     }catch(E1 e1)  {       System.out.println(“Caught El”);    }   } } 对上面的程序进行编译、运行,下面的叙述哪个是正确的:A:由于Qoiz6_1.main方法中没有声明抛出异常E1、E2,所以编译会失败
B:编译成功,输出为:    Caught E1
C:由于针对E2的catch程序块是无法执行到的,所以编译会失败
D:编译成功,输出为:    Caught El    Caught E2
答案: 【编译成功,输出为:    Caught E1】
6、单选题:设有如下代码段       1 String s = null;      2 if ( s != null & s.length() > 0)      3 System.out.println(“s != null & s.length() > 0”);
4 if ( s != null && s.length() > 0)      5 System.out.println(“s != null & s.length() > 0”);
6 if ( s != null || s.length() > 0)      7 System.out.println(“s != null & s.length() > 0”);
8  if ( s != null | s.length() > 0)      9 System.out.println(“s != null | s.length() > 0”);                    哪些行将抛出空指针异常?  假设在检查过程中把抛出异常的if语句注释掉继续验证.
A:2,4
B:6,8
C:2,6,8
D:2,4,6,8
答案: 【2,6,8】
7、单选题:当2个实际参数分别为4和0时,以下方法调用的执行结果为:public void divide(int a, int b) {    try {      int c = a / b;     } catch (Exception e) {         System.out.print(“Exception “);     } finally {       System.out.println(“Finally”);     }  }
A:输出 Exception
B:输出 Finally
C: 输出 Exception Finally
D:无输出
答案: 【 输出 Exception Finally 】
8、多选题:检查下面的代码:class E1 extends Exception{ }
class E2 extends E1 { }
public class Quiz6_5{
public static void main(String[] args){
try{
throw new E1();
}
// –X–
}
}
下列语句,哪一个可以放到–X–位置,而且保证编译成功。
A:catch(E2 x){}
B:catch(MyException x){ }
C:catch(El x){}
D:catch(Exception x){}
答案: 【catch(El x){};catch(Exception x){}】
9、多选题:检查下面的代码: class E1 extends Exception{ }; class E2 extends E1{ } class SuperQuiz6_2  {  } public class Quiz6_3 extends  SuperQuiz6_2{    public void f(Boolean flag) throws E1{    //一一X一一    } } 下列的语句,哪—个可以放到–X–位置,而且保证编译成功。
A:throw new E2();
B:throw new Exception();
C:throw new object();
D:throw new El();
答案: 【throw new E2();;throw new El();】
10、多选题:以下叙述那个正确?
A:一个try 块可跟任意个finally块.
B:一个try块必须至少跟一个finally 或 catch块.
C:如果catch 和 finally块均有,则catch 必须先于finally.
D: 每个try 块必须至少跟一个catch块.
答案: 【一个try块必须至少跟一个finally 或 catch块.;如果catch 和 finally块均有,则catch 必须先于finally.】

第十章 单元测试
1、单选题:在Applet的方法中,下列哪个方法将在关闭浏览器时执行,以释放Applet占用的资源?
A:init()
B:start()
C:destroy()
D:stop()
答案: 【destroy()】
2、单选题:关于以下代码所画图形的说明,正确的是? 1.g.setColor(Color.black); 2.g.drawLine(10,10,10,50); 3.g.setColor(Color.red);  4.g.drawRect(100,100,150,150);
A:一条40像素长的垂直黑线,一个边长为150像素的红色正方形
B:一条50像素长的垂直黑线,一个边长为150像素的红色正方形
C:一条40像素长的垂直红线,一个边长为150像素的红色正方形
D:一条50像素长的垂直红线,一个边长为150像素的红色正方形
答案: 【一条40像素长的垂直黑线,一个边长为150像素的红色正方形】
3、单选题:paint()方法使用哪种类型的参数?
A:Color
B:Graphics
C: String
D:Graphics2D
答案: 【Graphics 】
4、单选题:下列Applet类的方法中,在Applet的整个生命周期里至多只能执行一次的是?
A:repaint();
B:init();
C:stop();
D:start();
答案: 【init();】
5、单选题:为了向一个Applet传递参数,可以在HTML文件的APPLET标签中使用PARAM选项,在Applet程序中获取参数时,应使用的方法是
A:getImage()
B:getDocumentBase()
C:getParameter()
D:getCodeBase()
答案: 【getParameter()】

第十一章 单元测试
1、单选题:下列哪个容器类使用时必须加入到其他的容器中?
A:Dialog
B: Window
C:Frame
D:Panel
答案: 【Panel】
2、单选题:在AWT中部件如何注册事件监听者?
A:调用监听者的addXXXListener()方法
B:调用部件的addXXXListener()方法
C:调用应用的addXXXListener()方法
D:调用事件addXXXListener()方法
答案: 【调用部件的addXXXListener()方法】
3、单选题:通过哪个方法可以改变按钮的颜色?
A:setForeground
B:getBackground
C:setBackground
D:setColor
答案: 【setBackground 】
4、单选题:新创建的 Frame是不可见的,使用哪个方法可使其可见
A:repaint()
B: setVisible(true)
C:dispose()
D:setSize(300,200)
答案: 【 setVisible(true)】
5、单选题:Frame的默认的布局管理器是下列哪一个
A:CardLayout
B:FlowLayout
C:GridLayout
D:BorderLayout
答案: 【BorderLayout 】
6、多选题:有关事件监听者以下哪个为真?
A:一个监听者只能处理来自一个部件的事件.
B:一个监听者可处理来自多个部件的事件.
C:一个部件可有多个监听者
D:一个部件只能有一个监听者
答案: 【一个监听者可处理来自多个部件的事件.;一个部件可有多个监听者】
7、多选题:哪个方法可得到WindowEvent中的事件源?
A:getWindow()
B:getSource()
C:getID()
D:getFrame()
答案: 【getWindow();getSource()】

第十二章 单元测试
1、单选题:哪个关键字用于与锁标记打交道?
A:abstract
B:static
C:native
D:synchronized
答案: 【synchronized】
2、单选题:线程在生命周期要经历5种状态,如果线程当前是新建状态,则它可到达的下一个状态是?
A:可运行状态
B:运行状态
C:终止状态
D:阻塞状态
答案: 【可运行状态】
3、单选题:以下哪个方法用来定义线程的执行体?
A:init()
B:main()
C:start()
D:run()
答案: 【run()】
4、单选题:下面说法不正确的是( )
A:Java中的线程可以共享代码
B:Java中线程是抢占式的
C:Java中线程是分时的
D:Java中的线程可以共享数据
答案: 【Java中线程是分时的】
5、多选题:下列程序的功能是在监控台上每一秒种显示一个字符串“Hello!”,能够填写在线程中下划线位置,使程序完整并能正确运行的语句是
public class Test implements Runnable{
public static void main(String args[]){
Test t=new Test();
Thread tt=new Thread(t);
tt.start();
}
public void run(){
for(;;){
try {          ________;
} catch(________e){ }
System.out.println(“Hello”);
}
}
}
A:Thread.sleep(1000)  InterruptedException
B:sleep(1000)  InterrutpedException
C:t.sleep(1000)  InterruptedException
D:Thread.sleep(1000)  RuntimeException
答案: 【Thread.sleep(1000)  InterruptedException;sleep(1000)  InterrutpedException】

第十三章 单元测试
1、单选题:用DataOuputStream的哪个方法写一个字符串到顺序文件?
A:writeSTR
B:writeString
C:writeUTF
D:writeInt
答案: 【writeUTF】
2、单选题:在读文件employ.dat时,使用该文件名作为字符串参数的类是?
A:DataInputStream
B:DataOutputStream
C:FileInputStream
D:BufferedReader
答案: 【FileInputStream】
3、单选题:给一个已存在的文件report,用FileWriter(“report”)创建对象并给其写入数据,则结果为?
A:由于文件已存在,将抛出异常;
B:数据添加到文件中;
C:文件内容被新内容替换;
D:数据写入到文件的随机位置。
答案: 【文件内容被新内容替换;】
4、单选题:以下哪个是使用RandomAccessFile构造方法的合法方式?
A:new RandomAccessFile(“read”, “data”);
B:new RandomAccessFile(“data”, “read”);
C:new RandomAccessFile(“r”, “data”);
D:new RandomAccessFile(“data”, “r”);
答案: 【new RandomAccessFile(“data”, “r”);】
5、单选题:在File类提供的方法中,用于创建目录的方法是?
A:mkdir()
B:mkdirs()
C:listFiles()
D:list()
答案: 【mkdir()】

第十四章 单元测试
1、单选题:关于泛型,以下哪个叙述为假?
A:JDK1.4版本不支持泛型
B:泛型参数定义时允许使用extends子句进行限定
C:泛型的本质是参数化类型
D:泛型的类型参数允许基本类型
答案: 【泛型的类型参数允许基本类型】
2、单选题:关于java.util.Collections类的叙述,以下哪个为真?
A:Collections类提供有sort方法用于对列表的排序;
B:Collections类提供有sort方法可用于对集合的排序;
C:Collections类实现Collection接口;
D:Collections类的addALL方法每次只能加1个数据到集合中。
答案: 【Collections类提供有sort方法用于对列表的排序;】
3、单选题:欲构造ArrayList类的一个实例,元素类型为String,作为List类型的对象,下列哪个方法是正确的 ?
A:List<String>  myList=new List<String> ();
B:List<String>  myList=new ArrayList<String> ();
C:ArrayList  myList=new Object();
D:ArrayList<String> myList=new List<String> ();
答案: 【List<String>  myList=new ArrayList<String> ();】
4、单选题:类 java.util.HashMap 实现的接口是?
A:java.util.Collection
B:java.util.Map
C:java.util.List
D:java.util.Set
答案: 【java.util.Map】
5、单选题:设有泛型类的定义如下
class Test<T> { }
则由该类创建对象时,使用正确的是?
A:Test<int> x = new Test<int>();
B:Test<T> x = new Test<T>();
C:Test x = new Test();
D:Test<Object> x = new Test<Object>();
答案: 【Test<Object> x = new Test<Object>();】

第十五章 单元测试
1、单选题:类JOptionPane中的哪个方法可以用来读取用户的输入数据
A:showInputDialog( )
B:read()
C:showMessageDialog( )
D:readLine()
答案: 【showInputDialog( )】
2、单选题:哪个方法给JFrame窗体加入菜单条?
A:setJMenu()
B:addJMenuBar()
C:add()
D:setJMenuBar()
答案: 【setJMenuBar()】
3、单选题:JPanel的默认布局管理器是?
A:BorderLayout
B:CardLayout
C:FlowLayout
D:GridLayout
答案: 【FlowLayout】
4、单选题:
JTextField 的事件监听器接口为?
A:JActionListener
B:ActionListener
C:ItemListener
D:ChangeListener
答案: 【ActionListener】
5、单选题:Swing部件中图形绘制一般是通过重写以下哪个方法?
A:paintComponent
B:paint
C:update
D:paintBorder
答案: 【paintComponent