background image

JAVA 笔试题

A. 行 4 与行 6

                     

都将执行

B. 行 4 执行,行 6 不执行

C. 行 6 执行,行 4

                   

不执行

D. 行 4、行 6 都不执行

17、下面程序的执行结果为:()

1. public class Test {

2.

  static Boolean foo(char c) {

3.      System.out.println(c);
4.      return true;
5.   }
6.   public static void main(String[] args) {

7.

     int i = 0;

8.

     for (foo(‘A’); foo(‘B’)&&(i<2); foo(‘C’)) {

9.

        i++;

10.

        foo(‘D’);

11.      }
12.   }
13. }
A. ABDCBDCB                    B. ABCDABCD
C. Compilation fails                C. An exception is thrown at runtime

18、阅读下面的程序

1. public class Outer {
2.    public void someOuterMethod() {
3.       //Line3
4.    }
5.    public class Inner() {}
6.    public static void main(String[] args) {
7.       Outer o = new Outer();
8.       //Line8
9.    }
10. }
Which instantiates is an instance of Inner? ()
A. new Inner(); // At line3          B. new Inner(); // At line 8
C. new o.Inner(); // At line 8        C. new Outer.inner(); // At line 8

19、选出能正确赋值的: 
  public class TestA { 
 

private int a; 

  

public int change(int m) { 

    

return m;   

  

  } 

public class TestB extend TestA{ 

  

public int b;  

 

public static void main() { 

   

TestA  aa = new TestA(); 

        TestB  bb = new TestB(); 

 

第 3     

页 共 8 页