打印

TEST

本帖已经被作者加入个人空间

TEST

十道选择题:
1. 下面哪一个选项合法构造并初始化了数组?(Choose one.)
A. int [] myList = {“1”, “2”, “3”};
B. int [] myList = (5, 8, 2);
C. int myList [] [] = {4,9,7,0};
D. int myList [] = {4, 3, 7};
E. int [] myList = [3, 5, 6];
F. int myList [] = {4; 6; 5};
2.允许一个类的成员访问同一包中其它类的成员的最受限的修饰符为? (Choose one.)
A. public
B. abstract
C. protected
D. synchronized
E. default access
3. Test3.java程序如下:
1. interface Base {
2.  boolean m1 ();
3.  byte m2(short s);
4. }
下面哪一个代码段将会正确编译? (Choose one.)
A. interface Base2 implements Base {}
B. abstract class Class2 extends Base {
public boolean m1() { return true; } }
C. abstract class Class2 implements Base {
public boolean m1() { return (7 > 4); } }
D. class Class2 implements Base {
boolean m1() { return false; }
byte m2(short s) { return 42; } }
4. Equals.java程序如下:
1. class Equals {
2.  public static void main(String [] args) {
3.   int x = 100;
4.   double y = 100.1;
5.   boolean b = (x = y);
6.   System.out.println(b);
7.  }
8. }
如编译并运行,其输出结果为以下哪一个?(Choose one.)
A. true
B. false
C. 编译时产生错误
D. 运行时产生错误
5. Test.java程序如下:
1. class Test {
2.  public static void main(String [] args) {
3.   int x= 0;
4.   int y= 0;
5.   for (int z = 0; z < 5; z++) {
6.    if (( ++x > 2 ) || (++y > 2)) {
7.     x++;
8.    }
9.   }
10.   System.out.println(x + " " + y);
11.  }
12. }
输出结果为?(Choose one.)
A. 5 3
B. 8 2
C. 8 3
D. 8 5
6. Test.java程序如下:
1. class Test {
2.  public static void main(String [] args) {
3.   int x=20;
4.   String sup = (x<15)?"small":(x<22)?"tiny":"huge";
5.   System.out.println(sup);
6.  }
7. }
则输出结果为?(Choose one.)
A. small
B. tiny
C. huge
D. Compilation fails
7. RTExcept.java程序如下:
1. public class RTExcept {
2.  public static void throwit () {
3.   System.out.print("throwit ");
4.   throw new RuntimeException();
5.  }
6.  public static void main(String [] args) {
7.   try {
8.    System.out.print("hello ");
9.    throwit();
10.   }
11.   catch (Exception re ) {
12.    System.out.print("caught ");
13.   }
14.   finally {
15.    System.out.print("finally ");
16.   }
17.   System.out.println("after ");
18.  }
19. }
输出结果为?(Choose one.)
A. hello throwit caught
B. 编译失败
C. hello throwit RuntimeException caught after
D. hello throwit RuntimeException
E. hello throwit caught finally after
F. hello throwit caught finally after RuntimeException
8. B.java程序如下:
class A {
public void baz() {
System.out.println("A");
}
}
public class B extends A {
public static void main(String [] args) {
A a = new B();
a.baz();
}
public void baz() {
System.out.println("B");
}
}
编译、运行将得到下面哪一个结果?(Choose one.)
A. A
B. B
C. Compilation fails.
D. An exception is thrown at runtime.
9. 哪一个class或interface定义了wait()、notify()、notifyAll()方法?(Choose one.)
A. Object
B. Thread
C. Runnable
D. Class
10. MyRunnable.java程序如下:
1. public class MyRunnable implements Runnable {
2.  public void run() {
3.   // some code here
4.  }
5. }
下面哪一段代码将创建并启动一个线程?(Choose one.)
A. new Runnable(MyRunnable).start();
B. new Thread(MyRunnable).run();
C. new Thread(new MyRunnable()).start();
D. new MyRunnable().start();
十道挑错题
1. Test.java程序如下:,
1. public class Test {
2.  public static void main(String [] abc) {
3.   unsigned int x = 10;
4.   for (int y=0; y<5; y++, x--)
5.   System.out.print(" " + x);
6.  }
7. }
指出哪一行有错误? (Choose one.)
A. 第2行
B. 第3行
C. 第4行
D.没有错误
2. TestCount.java程序如下:
1. interface Count {
2.  short counter = 0;
3.  void countUp();
4. }
5. public class TestCount implements Count {
6.
7.  public static void main(String [] abc) {
8.   TestCount t = new TestCount();
9.   t.countUp();
10.  }
11.  public void countUp() {
12.   for (int x = 6; x>counter; x--, ++counter) {
13.    System.out.print(" " + counter);
14.   }
15.  }
16. }
此程序的错误在于? (Choose one.)
A. 第2行
B. 第7行
C. 第8行
D. 第12行
3. Test3.java程序如下:
1. public class While {
2.  public void loop() {
3.   int x= 0;
4.   while ( 1 ) {
5.    System.out.print("x plus one is " + (x + 1));
6.   }
7.  }
8. }
此程序编译时将会提示哪些行有语法错误?(Choose one.)
A. 第1行.
B. 第1、4行.
C. 第1、4、5行
D. 第4行.
4. ChildClass.java程序如下:
1. class ParentClass {
2.  public int doStuff(int x) {
3.   return x * 2;
4.  }
5. }
6.
7. public class ChildClass extends ParentClass {
8.  public static void main(String [] args ) {
9.   ChildClass cc = new ChildClass();
10.   long x = cc.doStuff(7);
11.   System.out.println("x = " + x);
12.  }
13.
14.  public long doStuff(int x) {
15.   return x * 3;
16.  }
17. }
进行编译时,哪一行将出错?(Choose one.)
A. 第3行
B. 第10行
C. 第14行.
D. 第15行.
5. TestObj.java程序如下:
1.public class TestObj {
2.  public static void main (String [] args) {
3.   Object o = new Object() {
4.    public boolean equals(Object obj) {
5.     return true;
6.    }
7.   }
8.   System.out.println(o.equals("Fred"));
9.  }
10.}
如想正确编译,需要如何更正?(Choose one.)
A. 无需要更正。编译时,没有错误
B. 删除第4、5、6行
C. 删除第8行
D. 添加“;”在第7行末尾
6. TestPoly.java程序如下:
1. public class TestPoly {
2.  public static void main(String [] args ){
3.   Parent p = new Child();
4.  }
5. }
6.
7. class Parent {
8.  public Parent() {
9.   super();
10.   System.out.println("instantiate a parent");
11.  }
12. }
13.
14. class Child extends Parent {
15.  public Child() {
16.   System.out.println("instantiate a child");
17.   super();
18.  }
19. }
指出此程序的错误之处?(Choose one.)
A. 第3行将子对象赋值给一个父对象引用
B. 第9行,Parent类无父类,故不能调用super()方法
C. 第17行,super()方法调用应置于System.out.println(“instantiate a child”)语句之前
D. 此程序可以正常运行,无错误
7. MyThread.java程序如下:
1. public class MyThread extends Thread {
2.
3.  public static void main(String [] args) {
4.   MyThread t = new MyThread();
5.   t.run();
6.  }
7.
8.  public void run() {
9.   for(int i=1;i<3;++i) {
10.    System.out.print(i + "..");
11.   }
12.  }
13. }
编译并运行,则?(Choose one.)
A. 第4行错误,无法编译
B. 第5行错误,无法编译.
C. 可以正常编译,并输出:1..2..
D. 可以正常编译,并输出:1..2..3..
8. AbstractTest.java程序如下:
1. public class AbstractTest {
2.  public static void main(String[] args) {
3.   new B();
4.  }
5. }
6. abstract class A {
7.  public A(){
8.   System.out.println("hello");
9.  }
10. }
11. class B extends A {
12. }
编译并运行,则?(Choose one)
A. 可以正常编译,并输出”hello”
B. 第6行编译有错
C. 第7行编译有错
D. 第11行编译有错
9. InterfaceTest.java程序如下:
1. public class InterfaceTest {
2.  public static void main(String[] args) {
3.   new B() {
4.    public void x(){
5.     System.out.println("test");
6.    }
7.   };
8.  }
9. }
10. interface A {
11.  void x();
12. }
13. interface B extends A {
14. }
编译并运行,则?(Choose one.)
A. 正常编译,并输出”test”
B. 正常编译,不输出任何作息。
C. 第13行编译出错
D. 第3至7行编译出错
10. SuperThis.java程序如下:
1. public class SuperThis {
2.  public static void main(String[] args) {
3.   new B();
4.  }
5. }
6. class A {
7.  public A(){
8.   System.out.print ("A");
9.  }
10. }
11. class B extends A {
12. public B(Object obj){
13.  System.out.print ("B");
14. }
15. public B(){
16.  super();
17.  this(new Object());
18. }
19. }
编译程序并运行,则?(Choose one)
A. 正常编译,输出AB
B. 正常编译,无任何输出信息
C. 第16行编译错误,其应置于this()方法之后
D. 第17行编译错误,因为super()方法与this()方法不能同置于一个构造器内。


本帖隐藏的内容需要回复才可以浏览


[ 本帖最后由 lujunxiang 于 2008-2-9 15:52 编辑 ]

TOP

编辑了一下下,禁用 Smilies。

TOP

看看,试试能都过关

看看,试试能都过关

TOP


感谢一直以来您对我们的支持!
当前时区 GMT+8, 现在时间是 2008-9-8 14:01 京ICP证060528 号

Designed By 17DST