常州酌乒文化传播有限公司

當(dāng)前位置:

JAVA認(rèn)證歷年真題:SCJP考試真題和解析2

發(fā)表時間:2014/4/21 9:54:44 來源:互聯(lián)網(wǎng) 點擊關(guān)注微信:關(guān)注中大網(wǎng)校微信
關(guān)注公眾號

例題4:

Which of the following lines of code will compile without error?

A.

int i=0;

if (i) {

System.out.println(“Hi”);

}

B.

boolean b=true;

boolean b2=true;

if(b==b2) {

System.out.println(“So true”);

}

C.

int i=1;

int j=2;

if(i==1|| j==2)

System.out.println(“OK”);

D.

int i=1;

int j=2;

if (i==1 &| j==2)

System.out.println(“OK”);

解答:B, C

點評:選項A錯,因為if語句后需要一個boolean類型的表達(dá)式。邏輯操作有^、&、| 和 &&、||,但是“&|”是非法的,所以選項D不正確。

例題5:

Which two demonstrate a "has a" relationship? (Choose two)

A. public interface Person { }

public class Employee extends Person{ }

B. public interface Shape { }

public interface Rectandle extends Shape { }

C. public interface Colorable { }

public class Shape implements Colorable

{ }

D. public class Species{ }

public class Animal{private Species species;}

E. interface Component{ }

class Container implements Component{

private Component[] children;

}

解答:D, E

點評: 在Java中代碼重用有兩種可能的方式,即組合(“has a”關(guān)系)和繼承(“is a”關(guān)系)。“has a”關(guān)系是通過定義類的屬性的方式實現(xiàn)的;而“is a”關(guān)系是通過類繼承實現(xiàn)的。本例中選項A、B、C體現(xiàn)了“is a”關(guān)系;選項D、E體現(xiàn)了“has a”關(guān)系。

例題6:

Which two statements are true for the class java.util.TreeSet? (Choose two)

A. The elements in the collection are ordered.

B. The collection is guaranteed to be immutable.

C. The elements in the collection are guaranteed to be unique.

D. The elements in the collection are accessed using a unique key.

E. The elements in the collection are guaranteed to be synchronized

解答:A, C

點評:TreeSet類實現(xiàn)了Set接口。Set的特點是其中的元素惟一,選項C正確。由于采用了樹形存儲方式,將元素有序地組織起來,所以選項A也正確

相關(guān)鏈接JAVA認(rèn)證考試報考指南  考試論壇 考試知道   考試動態(tài)

(責(zé)任編輯:fky)

2頁,當(dāng)前第1頁  第一頁  前一頁  下一頁
最近更新 考試動態(tài) 更多>
连南| 顺平县| 仙居县| 格尔木市| 霍山县| 封丘县| 通辽市| 伊通| 宜黄县| 杭锦后旗| 托克逊县| 宽城| 潜山县| 孟津县| 上饶市| 仁布县| 辽宁省| 册亨县| 营山县| 天津市| 福安市| 灵武市| 阳东县| 安义县| 乌兰察布市| 景德镇市| 尉氏县| 芜湖县| 筠连县| 玛纳斯县| 洮南市| 泰和县| 江西省| 宿州市| 永春县| 赤壁市| 开江县| 阳原县| 克什克腾旗| 永平县| 札达县|