2013中興筆試題JSD1309

才智咖 人氣:2.57W

1. 下列程式碼的執行結果是:

2013中興筆試題JSD1309

public class GoTest {

public static void main(String[] args) {

Sente a = new Sente();

();

Goban b = new Goban();

();

Stone c = new Stone();

();

}

}

class Sente implements Go {

public void go() {

tln(“go in Sente”);

}

}

class Goban extends Sente {

public void go() {

tln(“go in Goban”);

}

}

class Stone extends Goban implements Go {

}

interface Go {

public void go();

}

A. go in Goban

go in Sente

go in Sente

B. go in Sente

go in Sente

go in Goban

C. go in Sente

go in Goban

go in Goban

D. go in Goban

go in Goban

go in Sente

正確答案:C

2. A類中有一個方法:protected int print(String str){},B類繼承A類,以下方法能在B類中重寫A類中print()方法的是: ()。

A.

public int print(String str){}

B.

private int print(String str){}

C.

private void print(String str){}

D.

public void print(String str){}

正確答案:A

3. List類的物件list中的元素為:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],現在想返回該list物件的子集合[5,6,7,8],需要做的操作是:

A. ist(5, 8);

B. ist(5, 9);

C. ist(4, 8);

D. ist(4, 9);

正確答案:B

4. 下列程式碼的執行結果是:

String test = “Test A. Test B. Test C.”;

String regex = “.s*”;

String[] result = t(regex);

for (String s : result)

t(s + ” “);

A. Test A Test B Test C

B. Test A. Test B. Test C.

C. Test . Test . Test .

D. A. B. C.

正確答案:A

5.

執行下面的程式:

int a = 100;

int b = 200;

a = a + b;

b = a – b;

a = a – b;

tln(“a=” + a + “, b=” + b);

輸出的結果是:()。

A. a=100, b=300

B. a=100, b=200

C. a=200, b=100

D. a=300, b=200

正確答案:C

6.

類A,B和C的定義如下:

public class A {

public void f() {

tln(“A.f()”);

}

}

public class B extends A {

public void f() {

tln(“B.f()”);

}

}

public class C {

public void g(A a) {

tln(“g(A a)”);

a.f();

}

public void g(B b) {

tln(“g(B b)”);

b.f();

}

}

執行下面程式:

C c = new C();

A a = new B();

c.g(a);

輸出的結果是:()。

A. g(A a)

A.f()

B. g(A a)

B.f()

C. g(B b)

A.f()

D. g(B b)

B.f()

正確答案:B

7.

下列程式碼編譯和執行的結果是()

public class Foo {

public static void main(String[] args) {

list = new yList();

(new B());

(new C());

for (A a : list) {

a.x();

a.y();

}

}

}

interface A {

void x();

}

class B implements A {

public void x() {}

public void y() {}

}

class C extends B {

public void x() {}

}

A.

程式碼執行沒有輸出

B.

執行時丟擲異常

C.

程式碼a.y();行,編譯錯誤

D.

程式碼 list = new yList();行,編譯錯誤