JAVA認(rèn)證歷年真題:SCJP考試真題和解析_第1頁
JAVA認(rèn)證歷年真題:SCJP考試真題和解析_第2頁
JAVA認(rèn)證歷年真題:SCJP考試真題和解析_第3頁
JAVA認(rèn)證歷年真題:SCJP考試真題和解析_第4頁
JAVA認(rèn)證歷年真題:SCJP考試真題和解析_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

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

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

Choosethethreevalididentifiersfromthoselistedbelow.

A.IDoLikeTheLongNameCiass

B.$byte

C.const

D._ok

E.3_case

解答:A,B,D

點(diǎn)評:Java中的標(biāo)示符必須是字母、美元符($)或下劃線(_)開頭。關(guān)鍵字與保留字不能作

為標(biāo)示符。選項(xiàng)C中的const是Java的保留字,所以不能作標(biāo)示符。選項(xiàng)E中的3_case以

數(shù)字開頭,違反了Java的規(guī)則。例題2:

Howcanyouforcegarbagecollectionofanobject?

A.Garbagecollectioncannotbeforced

B.CallSystem.gc().

C.CallSystem.gc(),passinginareferencetotheobjecttobegarbagecollected.

D.CallRuntime.gc().

E.Setallreferencestotheobjecttonewvalues(null,forexample).

解答:A

點(diǎn)評:在Java中垃圾收集是不能被強(qiáng)迫立即執(zhí)行的。調(diào)用System.gc()或Runtime.gc。靜態(tài)

方法不能保證垃圾收集器的立即執(zhí)行,因?yàn)?,也許存在著更高優(yōu)先級的線程。所以選項(xiàng)B、

D不正確。選項(xiàng)C的錯(cuò)誤在于,System.gc。方法是不接受參數(shù)的。選項(xiàng)E中的方法可以使

對象在下次垃圾收集器運(yùn)行時(shí)被收集。

例題3:

Considerthefollowingclass:

1.classTest(inti){

2.voidtest(inti){

3.System.out.println(4tIamanint.'');

4.)

5.voidtest(Strings){

6.System.out.printlnC'Iamastring.^^);

7.}8.9.publicstaticvoidmain(Stringargs){

10.Testt=newTest();

ll.charch"';

12.t.test(ch);

13.}

14.}

Whichofthestatementsbelowistrue?(Chooseone.)

A.Line5willnotcompile,becausevoidmethodscannotbeoverridden.

B.Line12willnotcompile,becausethereisnoversionoftest()thatrakesacharargument.

C.Thecodewillcompilebutwillthrowanexceptionatline12.

D.Thecodewillcompileandproducethefollowingoutput:Iamanint.

E.Thecodewillcompileandproducethefollowingoutput:IamaString.

解答:D

點(diǎn)評:在第12行,16位長的char型變量ch在編譯時(shí)會自動(dòng)轉(zhuǎn)化為一個(gè)32位長的int型,

并在運(yùn)行時(shí)傳給voidtest(inti)方法。

QuestionNo:1

Given:

1.publicclasstest(

2.publicstaticvoidmain(Stringargs){

3.inti=OxFFFFFFFl;

4.intj=?i;

5.

6.}

7.)

Whatisthedecimalvalueofjatline5?

A.O

B.1

C.14

D.-15

E.Anerroratline3causescompilationtofail.

F.Anerroratline4causescompilationtofail.

Answer:D

QuestionNo:2

Given:

Integeri=newInteger(42);

Long1=newLong(42);

Doubled=newDouble(42.0);

WhichtwoexpressionsevaluatetoTrue?(ChooseTwo)

A.(i==1)

B.(i=d)

C.(d==1)

D.(i.equals(d))

E.(d.equals(i))

F.(i.equals(42))

Answer:D,E

QuestionNo:3

Exhibit:

1.publicclasstest(

2.privatestaticintj=0;

3.

4.privatestaticbooleanmethodB(intk)(

5.j+=k;

6.returntrue;

6.)

7.

8.publicstaticvoidmethodA(inti){

9.booleanb:

10.b=i<lOlmethodB(4);

ll.b=i<1011methodB(8);

12.)

13.

14.publicstaticvoidmain(Stringargs}(

15.methodA(0);

16.system.out.println(j);

17.)

18.)

Whatistheresult?

A.TheprogramprintsA”

B.Theprogramprihatistheoutput?

Answer:5

QuestionNo:5

Given:

1.publicclassFoo{

2.publicstaticvoidmain(Stringargs){

3.StringBuffera=newStringBuffer(<<A>>);

4.StringBufferb=newStringBuffer("B”);

5.operate(a,b);

6.system.out.println{a++b);

7.)

8.staticvoidoperate(StringBufferx,StringBuffery){

9.x.append{y};

10.y=x;

11.)

12.)

Whatistheresult?

A.Thecodecompilesandprints

B.Thecodecompilesandprints"A,A”.

C.Thecodecompilesandprints

D.Thecodecompilesandprints

E.Thecodecompilesandprints"AB,AB”.

F.ThecodedoesnotcompilebecausecannotbeoverloadedforStringBuffer.Answer:DIII

QuestionNo:6

Exhibit:

1.Publicclasstest(

2.PublicstaticvoidstringReplace(Stringtext)(

3.Text=text.replace(?j?,?i?);

4.)

5.

6.publicstaticvoidbufferReplace(StringBuffertext)(

7.text=text.append(“C”)

8.)

9.

10.publicstaticvoidmain(Stringargs)(

11.StringtextString=newString('java'');

12.StringBuffertextBufferString=newStringBuffer(“java”);

13.

14.stringReplace(textString);

15.BufferReplace(textBuffer);

16.

17.System.out.printin(textString+textBuffer);

18.}

19.)

Whatistheoutput?

Answer:javajavaC

QuestionNo:7

Exhibit:

1.publicclasstest{

2.publicstaticvoidadd3(Integeri)}

3.intval=Value();

4.val+=3;

5.i=newInteger(val);

6.)

7.

8.publicstaticvoidmain(Stringargs[]){

9.Integeri=newInteger(0);

10.add3(i);

11.system.out.println(Value());

12.)

13.)

Whatistheresult?

A.Compilationwillfail.

B.Theprogramprints"0".

C.Theprogramprints"3”.

D.Compilationwillsucceedbutanexceptionwillbethrownatline3.Answer:B

QuestionNo:8

Given:

1.publicclassConstOver{

2.publicConstOver(intx,inty,intz){

3.}

4.)

WhichtwooverloadtheConstOverconstructor?(ChooseTwo)

A.ConstOver(){}

B.ProtectedintConstOver(){)

C.PrivateConstOver(intz,inty,bytex){}

D.PublicObjectConstOver(intx,inty,intz){}

E.PublicvoidConstOver(bytex,bytey,bytez){}

Answer:A,C

QuestionNo:9

Given:

1.publicclassMethodOver{

2.publicvoidsetVar(inta,intb,floatc){

3.)

4.}

WhichtwooverloadthesetVarmethod?(ChooseTwo)

A.PrivatevoidsetVar(inta,floatc,intb){}

B.ProtectedvoidsetVar(inta,intb,floatc){}

C.PublicintsetVar(inta,floatc,intb)(returna;)

D.PublicintsetVar(inta,intb,floatc)(returna;)

E.ProtectedfloatsetVar(inta,intb,floatc)(returnc;)

Answer:A,C

QuestionNo:10

Given:

1.classBaseClass{

2.Privatefloatx=l.Of;

3.protectedfloatgetVar()(returnx;)

4.)

5.classSubclassextendsBaseClass(

6.privatefloatx=2.0f;

7.//insertcodehere

8.)

Whichtwoarevalidexamplesofmethodoverriding?(ChooseTwo)

A.FloatgetVar(){returnx;}

B.PublicfloatgetVar(){returnx;}

C.FloatdoublegetVar(){returnx;}

D.PublicfloatgetVar(){returnx;}

E.PublicfloatgetVar(floatf){returnf;}

Answer:B,D

QuestionNo:11

Whichtwodemonstratean"isa,5relationship?(ChooseTwo)

A.publicinterfacePerson{}

publicclassEmployeeextendsPerson{}

B.publicinterfaceShape{}

publicclassEmployeeextendsShape{}

C.publicinterfaceColor{}

publicclassEmployeeextendsColor{}

D.publicclassSpecies{}

publicclassAnimal(privateSpeciesspecies;)

E.interfaceComponent{}

ClassContainerimplementsComponent(

PrivateComponent1]children;

)

Answer:D,E

QuestionNo:12

Whichstatementistrue?

A.Ananonymousinnerclassmaybedeclaredasfinal.

B.Ananonymousinnerclasscanbedeclaredasprivate.

C.Ananonymousinnerclasscanimplementmultipleinterfaces.

D.Ananonymousinnerclasscanaccessfinalvariablesinanyenclosingscope.

E.Constructionofaninstanceofastaticinnerclassrequiresaninstanceoftheenclosingouter

class.

Answer:DIII

QuestionNo13

Given:

1.packagefoo;

2.

3.publicclassOuter(

4.publicstaticclassInner(

5.)

6.)

Whichstatementistrue?

A.AninstanceoftheInnerclasscanbeconstructedwith“newOuter.Inner()”

B.Aninstanceoftheinnerclasscannotbeconstructedoutsideofpackagefoo.

C.Aninstanceoftheinnerclasscanonlybeconstructedfromwithintheouterclass.

D.Fromwithinthepackagebar,aninstanceoftheinnerclasscanbeconstructedwith”new

inner。"

Answer:A

QuestionNo14

Exhibit:

1.publicclassenclosingone(

2.publicclassinsideone{}

3.)

4.publicclassinertest(

5.publicstaticvoidmain(stringargs)(

6.enclosingoneeo=newenclosingone();

7.//insertcodehere

8.)

9.)

Whichstatemen

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(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

提交評論