会计考友 发表于 2012-8-4 12:33:16

2011年JAVA认证模拟题第二阶段(19)

  Q55.What is wrong with the following code?
  1. final class First {
  2. private int a = 1;
  3. int b = 2;
  4. }
  5. class Second extends First {
  6. public void method() {
  7. System.out.println(a+b);
  8. }
  9. }
  a. You cannot invoke println() without passing it a string.
  b. Because a is private, no classes other than First can access it.
  c. Second cannot extend First.
  d. final is not a valid keyword for a class.
  Q56.What is displayed when the following piece of code is executed.
  1. class Test extends Thread {
  2. public void run() {
  3. System.out.print(“1 “);
  4. yield();
  5. System.out.print(“2 “);
  6. suspend();
  7. System.out.print(“3 “);

  8. resume();

会计考友 发表于 2012-8-4 12:33:17

2011年JAVA认证模拟题第二阶段(19)

</p>  9. System.out.print(“4 “);
  10. }
  11 public static void main(String []args) {
  12. Test t = new Test();
  13. t.start();
  14. }
  15. }
  a. Nothing, this is not a valid way to create and start a thread.
  b. 1 2
  c. 1 2 3
  d. 1
  Q57.What must be true for the RunHandler class so that the instances of RunHandler can be used as written in the following code?
  1. class Test {
  2. public static void main(String args[]){
  3. Thread t = new Thread(new RunHandler());
  4. t.start();
  5. }
  6. }
  Select all valid answers ?
  a. RunHandler must only implement the java.lang.Runnable interface.
  b. RunHandler must only extend the Thread class.
  c. RunHandler must extend the Thread class or implement Runnable interface.
  d. RunHandler must provide a run() method declared as public and returning void.
  55. c
  56. b
  57. cd
页: [1]
查看完整版本: 2011年JAVA认证模拟题第二阶段(19)