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

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

  Q16.What will happen when we try to compile the following code.
  1. public void WhichArray( Object x ) {
  2. if( x instanceof int[] ) {
  3. int[] n = (int[]) x ;
  4. for( int i = 0 ; i < n.length ; i++ ){
  5. System.out.println(“integers = “ + n );
  6. }
  7. }
  8. if( x instanceof String[] ) {
  9. System.out.println(“Array of
  Strings”);
  10. }
  11. }
  a. The compiler objects to line 2 comparing an Object with an array.
  b. The compiler objects to line 3 casting an Object to an array of int primitives.
  c. The compiler objects to line 7 comparing an Object to an array of Objects.
  d. It compiles without error.

  Q17.Consider the following class

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

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

</p>  1. class Tester {
  2. void test (int i) { System.out.println (“int version”); }
  3. void test (String s) { System.out.println (“String version”); }
  4.
  5. public static void main (String args[]) {
  6. Tester c = new Tester ();
  7. char ch = 'p';
  8. c.test (ch);
  9. }
  10. }
  Which of the following statements below is true?(Choose one.)
  a. Line 3 will not compile, because void methods cannot be overridden.
  b. Line 8 will not compile, because there is no conversion of test() that takes a char argument.
  c. The code will compile and produce the follwing output “int version”
  d. The code will compile and produce the follwing output “String version”
  Q18.You are creating a ToolBase class which will be extended by other programmers. The ToolBase class contains a single abstract method, createTool. Which of the following statements are true?
  a. The ToolBase class must be declared abstract.
  b. Classes extending ToolBase must not be declared abstract.
  c. The ToolBase class must not be declared final.
  d. The following variable declaration is illegal in any context “ToolBase myTB;”
  16. d
  17. c
  18. ac
页: [1]
查看完整版本: 2011年JAVA认证模拟题第二阶段(6)