Sunjava認(rèn)證考試答案_第1頁
Sunjava認(rèn)證考試答案_第2頁
Sunjava認(rèn)證考試答案_第3頁
Sunjava認(rèn)證考試答案_第4頁
Sunjava認(rèn)證考試答案_第5頁
已閱讀5頁,還剩4頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

Sunjava認(rèn)證考試答案

1.Whatgetsprintedwhenthefollowingprogram

iscompiledandrun?

classTest{

publicstaticvoidmain(Stringargs[]){

inti;

do{

i++;

}while(i0);

System.out.println(i);

}

}

Select1correctanswer:

A.Theprogramdoesnotcompileasiisnotinitialized.

B.Theprogramcompilesbutdoesnotrun.

C.Theprogramcompilesandrunsbutdoesnotprintanything.

D.Theprogramprints0.

E.Theprogramprints1.

答案:A:假如沒有初始化便使用根本變量類型,會(huì)導(dǎo)致編譯時(shí)特別,程序不能編譯。

2.Whatgetsprintedwhenthefollowingprogram

iscompiledandrun?

publicclassXYZ{

publicstaticvoidmain(Stringargs[]){

inti,j,k;

for(i=0;i3;i++)

{

for(j=1;j4;j++)

{

for(k=2;k5;k++)

{

if((i==j)(j==k))

System.out.println(i);

}}}}}

Select1correctanswer:

A.0

B.1

C.2

D.3

E.4

答案:C

3.Giventhefollowingcode:

classBase{}

publicclassMyCastextendsBase{

staticbooleanb1=false;

staticinti=-1;

staticdoubled=10.1;

publicstaticvoidmain(Stringargv[]){

MyCastm=newMyCast();

Baseb=newBase();

//Here

}

}

Whichofthefollowing,ifinsertedatthecomment//Here

willallowthecodetocompileandrunwithouterror?

Select2correctanswers:

A.b=m;

B.m=b;

C.d=i;

D.b1=i;

解析:A從子類型到父類型的轉(zhuǎn)換是擴(kuò)展引用轉(zhuǎn)換,不需要在運(yùn)行時(shí)實(shí)行特別的動(dòng)作,不會(huì)在運(yùn)行時(shí)拋出特別。

B從超類型到子類型的”轉(zhuǎn)換是收縮引用轉(zhuǎn)換,需要在運(yùn)行時(shí)執(zhí)行測試,以查明實(shí)際的引用值是否是新類型的合法值.假如不是,則會(huì)拋出ClassCascException。在這里,b本身不是MyCast類型的值,因此會(huì)導(dǎo)致運(yùn)行時(shí)特別。

C從int到double的轉(zhuǎn)換是擴(kuò)展根本轉(zhuǎn)換,根本類型之間的擴(kuò)展轉(zhuǎn)換永久不會(huì)導(dǎo)致運(yùn)行時(shí)特別。但從int或long到float,或者是從long到double都可能導(dǎo)致精度喪失。

D不允許進(jìn)展int和boolean之間的類型轉(zhuǎn)換

答案:A、C

4.Giventhefollowingclasseswhichofthefollowing

willcompilewithouterror?

interfaceIFace{}

classCFaceimplementsIFace{}

classBase{}

publicclassObRefextendsBase{

publicstaticvoidmain(Stringargv[])

{

ObRefob=newObRef();

Baseb=newBase();

Objecto1=newObject();

IFaceo2=newCFace();

}

}

Select3correctanswers:

A.o1=o2;

B.b=ob;

C.ob=b;

D.o1=b;

解析:A任何對象都可以賦給Object類型的對象,正確

B子類賦給超類是擴(kuò)展引用轉(zhuǎn)換,可以進(jìn)展

C收縮引用轉(zhuǎn)換,錯(cuò)誤

D擴(kuò)展引用轉(zhuǎn)換,可以進(jìn)展

答案ABD

5.Whatistheresultofcompilingandrunningthefollowingcode?

1publicclassTest{

2staticinttotal=10;

3publicstaticvoidmain(Stringargs[]){

4newTest();

5}

6publicTest(){

7System.out.println(Intest);

8System.out.println(this);

9inttemp=this.total;

10if(temp5){

11System.out.println(temp);

12}

13}

14}

Select1correctanswer:

A.Theclasswillnotcompile

B.Thecompilerreportsanerroratline2

C.Thecompilerreportsanerroratline9

D.Thevalue10isoneoftheprintedelements

E.Theclasscompilesbutgeneratesaruntimeerror

答案:D由于test類沒有overridetoString方法,故在調(diào)用println(this)時(shí)會(huì)直接顯示類的有關(guān)信息。

6.Carefullyexaminethefollowingcode:

publicclassStaticTest{

static{System.out.println(Hithere);}

publicvoidprint(){

System.out.println(Hello);

}

publicstaticvoidmain(Stringargs[]){

StaticTestst1=newStaticTest();

st1.print();

StaticTestst2=newStaticTest();

st2.print();

}}

WhenwillthestringHitherebeprinted?

Select1correctanswer:

A.Never

B.Eachtimeanewinstanceiscreated

C.Once,whentheclassisfirstloadedintotheJVM

D.Onlywhenthestaticmethodiscalledexplicitly

答案C

Java虛擬機(jī)標(biāo)準(zhǔn)商定,類的初始化發(fā)生在首次主動(dòng)使用時(shí)。靜態(tài)變量和靜態(tài)初始化塊的先后,實(shí)際上取決于它們在類中消失的先后挨次。

7.Giventhefollowingcodewhatistheeffectofabeing5?

publicclassTest{

publicvoidadd(inta){

loop:for(inti=1;i3;i++){

for(intj=1;j3;j++){

if(a==5){

breakloop;

}

System.out.println(i*j);

}

}

}

}

Select1correctanswer:

A.Generatesaruntimeerror

B.Throw

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論