Java程序员认证模拟题及详细分析_第1页
Java程序员认证模拟题及详细分析_第2页
Java程序员认证模拟题及详细分析_第3页
Java程序员认证模拟题及详细分析_第4页
Java程序员认证模拟题及详细分析_第5页
已阅读5页,还剩136页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Java程序员认证模拟题及详细分析资料仅供参考一.说明:(真实考试)

1.考试形式:网络计算机

2.考题形式:多选,单选,简答

3.题量:60

4.考试时间:120分钟

二.模拟题

1.Whichstatementaboutthegarbagecollectionmechanismaretrue?

A.Garbagecollectionrequireadditionalprogramecodeincaseswheremultiplethreadsarerunning.

B.Theprogrammercanindicatethatareferencethroughalocalvariableisnolongerofinterest.

C.TheprogrammerhasamechanismthatexplicityandimmediatelyfreesthememoryusedbyJavaobjects.

D.ThegarbagecollectionmechanismcanfreethememoryusedbyJavaObjectatexplectiontime.

E.Thegarbagecollectionsystemneverreclaimsmemoryfromobjectswhilearestillaccessibletorunninguserthreads.

2.Givethefollowingmethod:

1)publicvoidmethod(){

2)Stringa,b;

3)a=newString(“helloworld”);

4)b=newString(“gameover”);

5)System.out.println(a+b+”ok”);

6)a=null;

7)a=b;

8)System.out.println(a);

9)}

Intheabsenceofcompileroptimization,whichistheearliestpointtheobjectareferedisdefinitelyelibiletobegarbagecollection.

A.beforeline3

B.beforeline5

C.beforeline6

D.beforeline7

E.Beforeline9

3.Intheclassjava.awt.AWTEvent,whichistheparentclassuponwhichjdk1.1awteventsarebasedthereisamethodcalledgetIDwhichphraseaccuratelydescribesthereturnvalueofthismethod?

A.Itisareferencetotheobjectdirectlyaffectedbythecauseoftheevent.

B.Itisanindicationofthenatureofthecauseoftheevent.

C.Itisanindicationofthepositionofthemousewhenitcausedtheevent.

D.Inthecaseofamouseclick,itisanindicationofthetextunderthemouseatthetimeoftheevent.

E.Ittellsthestateofcertainkeysonthekeybordatthetimeoftheevent.

F.Itisanindicationofthetimeatwhichtheeventoccurred.

4.Whichstatementaboutlisteneristrue?

A.Mostcomponentallowmultiplelistenerstobeadded.

B.Ifmultiplelistenerbeaddtoasinglecomponent,theeventonlyaffectedonelistener.

C.Componentdon?tallowmultiplelistenerstobeadd.

D.ThelistenermechanismallowsyoutocallanaddXxxxListenermethodasmanytimesasisneeded,specifyingasmanydifferentlistenersasyourdesignrequire.

5.Givethefollowingcode:

publicclassExample{

publicstaticvoidmain(Stringargs[]){

intl=0;

do{

System.out.println(“Doingitforlis:”+l);

}while(--l>0)

System.out.println(“Finish”);

}

}

Whichwellbeoutput:

A.Doingitforlis3

B.Doingitforlis1

C.Doingitforlis2

D.Doingitforlis0

E.Doingitforlis?C1

F.Finish

见1-5题答案

答案及详细分析:

1。B、E

JAVA的垃圾回收机制是经过一个后台系统级线程对内存分配情况进行跟踪实现的,对程序员来说是透明的,程序员没有任何方式使无用内存显示的、立即的被释放。而且它是在程序运行期间发生的。

答案B告诉我们程序员能够使一个本地变量失去任何意义,例如给本地变量赋值为“null”;答案E告诉我们在程序运行期间不可能完全释放内存。

2。D

第6行将null赋值给a以后,a以前保存的引用所指向的内存空间就失去了作用,它可能被释放。因此对象a可能最早被垃圾回收是在第7行以前,故选择D选项。

3。B

请查阅JAVA类库。getID方法的返回值是“eventtype”。在认证考试中,总会有类似的书本以外的知识,这只能靠多实践来增长知识了。

4。A、D

控件能够同时使用多个“addXxxxListener”方法加入多个监听器。而且当多个监听器加入到同一控件中时,事件能够响应多个监听器,响应是没有固定顺序的。

5。D、F

本题主要考察考生对流程控制的掌握情况。这是当型循环,条件为真执行,条件为假则退出。循环体至少执行一次,故会输出D。循环体以外的语句总会被执行,故输出F。

6.Givethecodefragment:

1)switch(x){

2)case1:System.out.println(“Test1”);break;

3)case2:

4)case3:System.out.println(“Test2”);break;

5)default:System.out.println(“end”);

6)}

whichvalueofxwouldcause“Test2”totheoutput:

A.1

B.2

C.3

D.default

7.Giveincompletedmethod:

1)

2){if(unsafe()){//dosomething…}

3)elseif(safe()){//dotheother…}

4)}

Themethodunsafe()wellthroeanIOException,whichcompletesthemethodofdeclarationwhenaddedatlineone?

A.publicIOExceptionmethodName()

B.publicvoidmethodName()

C.publicvoidmethodName()throwIOException

D.publicvoidmethodName()throwsIOException

E.publicvoidmethodName()throwsException

8.Givethecodefragment:

if(x>4){

System.out.println(“Test1”);}

elseif(x>9){

System.out.println(“Test2”);}

else{

System.out.println(“Test3”);}

Whichrangeofvaluexwouldproduceofoutput“Test2”?

A.x<4

B.x>4

C.x>9

D.None

9.Givethefollowingmethod:

publicvoidexample(){

try{

unsafe();

System.out.println(“Test1”);

}catch(SafeExceptione){System.out.println(“Test2”);

}finally{System.out.println(“Test3”);}

System.out.println(“Test4”);

Whichwilldisplayifmethodunsafe()runnormally?

A.Test1

B.Test2

C.Test3

D.Test4

10.Whichmethodyoudefineasthestartingpointofnewthreadinaclassfromwhichnewthethreadcanbeexcution?

A.publicvoidstart()

B.publicvoidrun()

C.publicvoidint()

D.publicstaticvoidmain(Stringargs[])

E.publicvoidrunnable()

6-10答案:

6。B.C

在开关语句中,标号总是不被当做语句的一部分,标号的作用就是做为条件判断而已,一旦匹配成功,就执行其后的语句,一直遭遇break语句为止。(包括default语句在内)

7。D、F

IOException异常类是Exception的子类。根据多态性的定义,IOException对象也能够被认为是Exception类型。还要注意在方法声明中抛出异常应用关键字“throws”。

8。D

只有两种情况:大于4时输出“Test1”,小于等于4时输出“Test3”。

9。A、C、D

在正常情况下,打印Test1、Test3、Test4;在产生可捕获异常时打印Test2、Test3、Test4;在产生不可捕获异常时,打印Test3,然后终止程序。注意finally后面的语句总是被执行。

10。B

线程的执行是从方法“run()”开始的,该方法是由系统调用的。程序员手工调用方法start(),使线程变为可运行状态。

11.Giventhefollowingclassdefinition:

classA{

protectedinti;

A(inti){

this.i=i;

}

}

whichofthefollowingwouldbeavalidinnerclassforthisclass?

Selectallvalidanswers:

A.classB{

}

B.classBextendsA{

}

C.classBextendsA{

B(){System.out.println(“i=”+i);}

}

D.classB{

classA{}

}

E.classA{}

12.Whichmodifiershouldbeappliedtoamethodforthelockofobjectthistobeobtainedpriortoexcutionanyofthemethodbody?

A.synchronized

B.abstract

C.final

D.static

E.public

13.ThefollowingcodeisentirecontentsofafilecalledExample.java,causespreciselyoneerrorduringcompilation:

1)classSubClassextendsBaseClass{

2)}

3)classBaseClass(){

4)Stringstr;

5)publicBaseClass(){

6)System.out.println(“ok”);}

7)publicBaseClass(Strings){

8)str=s;}}

9)publicclassExample{

10)publicvoidmethod(){

11)SubClasss=newSubClass(“hello”);

12)BaseClassb=newBaseClass(“world”);

13)}

14)}

Whichlinewouldbecausetheerror?

A.9B.10C.11D.12

14.Whichstatementiscorrectlydeclareavariableawhichissuitableforreferingtoanarrayof50stringemptyobject?

A.String[]a

B.Stringa[]

C.chara[][]

D.Stringa[50]

F.Objecta[50]

15.Givethefollowingjavasourcefragement:

//pointx

publicclassInteresting{

//dosomething

}

WhichstatementiscorrectlyJavasyntaxatpointx?

A.importjava.awt.*;

B.packagemypackage

C.staticintPI=3.14

D.publicclassMyClass{//dootherthing…}E.classMyClass{//dosomething…}

11-15答案:

11。A

此题考查内部类及关键字“super”的用法。内部类不能与外部类同名。另外,当B继承A时,A中的构造函数是带参数的,B中缺省构造函数的函数体为空;而JAVA编译器会为空构造函数体自动添加语句“super();”调用父类构造函数,更进一步是调用父类的参数为空的构造函数。而父类中没有参数为空的构造函数。

12。A

此关键字能够在两个线程同时试图访问某一数据时避免数据毁损。

13。C

当一个类中未显式定义构造函数时,缺省的构造函数是以类名为函数名,参数为空,函数体为空。虽然父类中的某一构造函数有字符串参数s,可是子类继承父类时并不继承构造函数,因此它只能使用缺省构造函数。故在第11行出错。

14。A、B

注意,题中问的是如何正确声明一个一维数组,并非实例化或者初始化数组

15。A、E

X处能够是一个输入,包的定义,类的定义。由于常量或变量的声明只能在类中或方法中,故不能选择C;由于在一个文件中只能有一个public类,故不能选择D。

16.Givethisclassoutline:

classExample{

privateintx;

//restofclassbody…

}

AssumingthatxinvokedbythecodejavaExample,whichstatementcanmadexbedirectlyaccessibleinmain()methodofExample.java?

A.Changeprivateintxtopublicintx

B.changeprivateintxtostaticintx

C.Changeprivateintxtoprotectedintx

D.changeprivateintxtofinalintx

17.thepieceofpreliminaryanalsisworkdescribesaclassthatwillbeusedfrequentlyinmanyunrelatedpartsofaproject

“Thepolygonobjectisadrawable,Apolygonhasvertexinformationstoredinavector,acolor,lengthandwidth.”

WhichDatatypewouldbeused?

A.Vector

B.int

C.String

D.Color

E.Date

18.Aclassdesignrequiresthatamembervariableshouldbeaccessibleonlybysamepackage,whichmodiferwordshouldbeused?

A.protected

B.public

C.nomodifer

D.private

19.Whichdeclaresfornativemethodinajavaclasscorrected?

A.publicnativevoidmethod(){}

B.publicnativevoidmethod();

C.publicnativemethod();

D.publicvoidmethod(){native;}

E.publicvoidnativemethod();

20.Whichmodifershouldbeappliedtoadeclarationofaclassmembervariableforthevalueofvariabletoremainconstantafterthecreationoftheobject?

16-20答安:

16。B

静态方法除了自己的参数外只能直接访问静态成员。访问非静态成员,必须先实例化本类的一个实例,再用实例名点取。

17。A、B、D

polygon的顶点信息存放在Vector类型的对象内部,color定义为Color,length和width定义为int。

注意,这是考试中常见的题型。

18。C

此题考点是高级访问控制。请考生查阅高级访问控制说明表格。

19。B

native关键字指明是对本地方法的调用,在JAVA中是只能访问但不能写的方法,它的位置在访问权限修饰语的后面及返回值的前面。

20。final

定义常量的方法是在变量定义前加final关键字。

21.Whichisthemain()methodreturnofaapplication?

A.String

B.byte

C.char

D.void

22.Whichiscorrectedargumentofmain()methodofapplication?

A.Stringargs

B.Stringar[]

C.Charargs[][]

D.StringBufferarg[]

23.“TheEmployeeobjectisaperson,AnEmployeehasappointmentstoreinavector,ahiredateandanumberofdependent”

shortanswer:useshorteststatementdeclareaclassofEmployee.

24.Givethefollowingclassdefinationinseparatesourcefiles:

publicclassExample{

publicExample(){//dosomething}

protectedExample(inti){//dosomething}

protectedvoidmethod(){//dosomething}

}

publicclassHelloextendsExample{//membermethodandmembervariable}

WhichmethodsarecorrectedaddedtotheclassHello?

A.publicvoidExample(){}

B.publicvoidmethod(){}

C.protectedvoidmethod(){}

D.privatevoidmethod(){}

25.Floats=newFloat(0.9F);

Floatt=newFloat(0.9F);

Doubleu=newDouble(0.9);

Whichexpression?sresultistrue?

A.s==t

B.s.equals(t)

C.s==u

D.t.equals(u)

21-15答案:

21。D

main()方法没有返回值,因此必须用void修饰。main()方法的返回值不能任意修改。

22。B

main()方法的参数是字符串数组,参数名能够任意定义。

23。publicclassEmployeeextendsPerson

这也是真实考试中常见的一种题型。要注意题目叙述中“isa”表示“extends”的含义。

24。A、B、C

考察的知识点是方法覆盖,其中要注意的是方法覆盖时,子类方法的访问权限不能小于父类方法的访问权限。另外,选项A并不是父类构造函数,它是子类中的新方法。

25。A、B

考察“==”及方法“equals()”的用法。注意以下几点区别:

1)引用类型比较引用;基本类型比较值。

2)equals()方法只能比较引用类型,“==”可比较引用及基本类型。

3)当用equals()方法进行比较时,对类File、String、Date及封装类(WrapperClass)来说,是比较类型及内容。

4)用“==”进行比较时,符号两边的数据类型必须一致(可相互转换的基本类型除外),否则编译出错。26.Givefollowingclass:

classAClass{

privatelongval;

publicAClass(longv){val=v;}

publicstaticvoidmain(Stringargs[]){

AClassx=newAClass(10L);

AClassy=newAClass(10L);

AClassz=y;

longa=10L;

intb=10;

}

}

Whichexpressionresultistrue?

A.a==b;

B.a==x;

C.y==z;

D.x==y;

E.a==10.0;

27.Asocketobjecthasbeencreatedandconnectedtoastandardinternetserviceonaremotenetworkserver.WhichconstructiongivethemostsuitablemeansforreadingASCIIdataonlineatatimefromthesocket?

A.InputStreamin=s.getInputStream();

B.DataInputStreamin=newDataInputstream(s.getInputStream());

C.ByteArrayInputStreamin=newByteArrayInputStream(s.getInputStream());

D.BufferedReaderin=newBufferedReader(newInputStreamReader(s.getInputStream()));

E.BufferedReaderin=newBufferedReader(newInputStreamReader(s.getInputStream()),”8859-1”);

28.Strings=”ExampleString”;

Whichoperationislegal?

A.s>>>=3;

B.inti=s.length();

C.s[3]=”x”;

D.Stringshort_s=s.trim();

E.Stringt=”root”+s;

29.Whathappenswhenyoutrytocompileandrunthefollowingprogram?

classMystery{

Strings;

publicstaticvoidmain(String[]args){

Mysterym=newMystery();

m.go();

}

voidMystery(){

s=”constructor”;

}

voidgo(){

System.out.println(s);

}

}

A.thiscodewillnotcompile

B.thiscodecomplilesbutthrowsanexceptionatruntime

C.thiscoderunsbutnothingappearsinthestandardoutput

D.thiscoderunsand“constructor”inthestandardoutput

E.thiscoderunsandwrites”null”inthestandardoutput

30.WhatusetopositionaButtoninaFrame,onlywidthofButtonisaffectedbytheFramesize,whichLayoutButtonwellbeset?

A.FlowLayout;

B.GridLayout;

C.NorthofBorderLayout

D.SouthofBorderLayout

E.EastorWestofBorderLayout

31.WhatusetopositionaButtoninaFrame,sizeofButtonisnotaffectedbytheFramesize,whichLayoutButtonwillbeset?

A.FlowLayout;

B.GridLayout;

C.NorthofBorderLayout

D.SouthofBorderLayout

E.EastorWestofBorderLayout

32.AnAWTGUIunderexposurecondition,whichoneormoremethodwellbeinvokewhenitredraw?

A.paint();

B.update();

C.repaint();

D.drawing();

33.SelectvalididentifierofJava:

A.userName

B.%passwd

C.3d_game

D.$chargeE.this

34.WhichareJavakeyword?

A.goto

B.null

C.FALSE

D.native

E.const

35.Runacorrectedclass:java?CcsAClassabc

Whichstatementistrue?

A.args[0]=”-cs”;

B.args[1]=”abc”;

C.args[0]=”java”;

D.args[0]=”a”;E.args[1]=?b?

36.Givethefollowingjavaclass:

publicclassExample{

staticintx[]=newint[15];

publicstaticvoidmain(Stringargs[]){

System.out.println(x[5]);

}

}

Whichstatementiscorrected?

A.Whencompile,someerrorwilloccur.

B.Whenrun,someerrorwilloccur.

C.Outputiszero.

D.Outputisnull.

37.Givethefollowingjavaclass:

publicclassExample{

publicstaticvoidmain(Stringargs[]){

staticintx[]=newint[15];

System.out.println(x[5]);

}

}

Whichstatementiscorrected?

A.Whencompile,someerrorwilloccur.

B.Whenrun,someerrorwilloccur.

C.Outputiszero.

D.Outputisnull.

38.Shortanswer:

Thedecimalvalueofiis12,theoctalivalueis:

39.Shortanswer:

Thedecimalvalueofiis7,thehexadecimalivalueis:

40.Whichistherangeofchar?

A.27~27-1

B.0~216-1

C.0~216

D.0~28

41.Whichistherangeofinttype?

A.-216~216-1

B.-231~231-1

C.-232~232-1

D.-264~264-1

42.Givethefollowingclass:

publicclassExample{

Stringstr=newString(“good”);

charch[]={

publicstaticvoidmain(Stringargs[]){

Exampleex=newExample();

ex.change(ex.str,ex.ch);

System.out.println(ex.str+”and”+ex.ch);

}

publicvoidchange(Stringstr,charch[]){

str=”testok”;ch[0]=?g?

}

}

Whichistheoutput:

A.goodandabc

B.goodandgbc

C.testokandabc

D.testokandgbc

43.WhichcodefragmentswouldcorrectlyidentifythenumberofargumentspassedviacommandlinetoaJavaapplication,excludethenameoftheclassthatisbeinginvoke.

A.intcount=args.length;

B.intcount=args.length-1;

C.intcount=0;while(args[count]!=null)

count++;

D.intcount=0;while

(!(args[count].equals(“”)))count++;

44.FilterOutputStreamistheparentclassforBufferedOutputStream,DataOutputStreamandPrintStream.WhichclassesarevalidargumentfortheconstructorofaFilterOutputStream?

A.InputStream

B.OutputStream

C.File

D.RandomAccessFile

E.StreamTokenizer

45.GivenaTextAreausingaproportionalpitchfontandconstructedlikethis:

TextAreat=newTextArea(“12345”,5,5);

Whichstatementistrue?

A.Thedisplayedwidthshowsexactlyfivecharactersoneeachlineunlessotherwiseconstrained

B.Thedisplayedheightisfivelinesunlessotherwiseconstrained

C.Themaximumnumberofcharactersinalinewillbefive

D.Theuserwillbeabletoeditthecharacterstring

E.Thedisplayedstringcanusemultiplefonts

46.GivenaListusingaproportionalpitchfontandconstructedlikethis:

Listl=newList(5,true);

Whichstatementistrue?

A.Thedisplayeditemexactlyfivelinesunlessotherwiseconstrained

B.Thedisplayeditemisfivelinesinit,butcandisplayedmorethanfiveItembyscroll

C.Themaximumnumberofiteminalistwillbefive.

D.Thelistismultiplemode

47.Giventhisskeletonofaclasscurrentlyunderconstruction:

publicclassExample{

intx,y,z;

publicExample(inta,intb){

//lotsofcomplexcomputation

x=a;y=b;

}

publicExample(inta,intb,intc){

//doeverythingthesameassingleargument

//versionofconstructor

//includingassignmentx=a,y=b,z=c

z=c;

}

}

Whatisthemostconcisewaytocodethe“doeverything…”partoftheconstructortakingtwoarguments?

Shortanswer:

48.Whichcorrectlycreateatwodimensionalarrayofintegers?

A.inta[][]=newint[][];

B.inta[10][10]=newint[][];

C.inta[][]=newint[10][10];

D.int[][]a=newint[10][10];

E.int[]a[]=newint[10][10];

49.Whicharecorrectclassdeclarations?AssumeineachcasethatthetextconstitutestheentirecontentsofafilecalledFred.java?

A.publicclassFred{

publicintx=0;

publicFred(intx){

this.x=x;

}

}

B.publicclassfred{

publicintx=0;

publicFred(intx){

this.x=x;

}

}

C.publicclassFredextendsMyBaseClass,MyOtherBaseClass{

publicintx=0;

publicFred(intxval){

x=xval;

}

}

D.protectedclassFred{

privateintx=0;

privateFred(intxval){

x=xval;

}

}

E.importjava.awt.*;

publicclassFredextendsObject{

intx;

privateFred(intxval){

x=xval;

}

}

50.Aclassdesignrequiresthataparticularmembervariablemustbeaccessiblefordirectaccessbyanysubclassesofthisclass.butotherwisenotbyclasseswhicharenotmembersofthesamepackage.Whatshouldbedonetoachievethis?

A.Thevariableshouldbemarkedpublic

B.Thevariableshouldbemarkedprivate

C.Thevariableshouldbemarkedprotected

D.Thevariableshouldhavenospecialaccessmodifier

E.Thevariableshouldbemarkedprivateandanaccessormethodprovided

答案及详细分析:

26。A、C、E

考察的知识点是比较基本类型与对象类型的不同之处,基本类型进行的是值比较,而对象类型进行的是地址比较,也就是对指向它们内存地址的指针进行比较。

27。E

在程序中实现字节与字符转换时,采用规范“ISO8859-1”是最适宜的方式。

28。B、D、E

移位操作只对整型有效,故不能选A;String类型并非数组,故不能用C所示方法取其中的某一位;B中的length方法返回字符串长度;D中trim方法返回字符串去掉其前后的空格后的新字符串;字符串能够用“+”进行合并。

29。E

回答本题时要细心阅读程序,注意“voidMistery(){}”并非构造函数,因为构造函数是没有返回值时,它只是与类名一致的方法名而已。注意到这一点,此题就没有什么难度了。

30。C、D

考察对布局管理器知识的掌握情况。BorderLayout的特性是当容器的尺寸改变时,North、South、West、East位置控件的较窄边长度不变,较长边长度变化。但控件的相对位置不变。

31。A

FlowLayout的特性是其中的控件大小不随着容器尺寸的变化而变化,但控件的相对位置会有所改变。

32。A(多选)

请注意,此题虽然是多选题,但正确答案只有一个。不论在什么情况下,图形要进行重绘,最终总会调用paint()方法,而且也只有paint()方法总会被调用。

33。A、D

Java中的标识符是以字符开头,字符包括字母、下划线“_”、美圆符“$”。不能以数字开头,也不能是Java关键字。

34。A、B、D、E

注意:goto、const是Java关键字,可是不使用。

35。D

cs是运行时可选择的java命令的参数,类名后才是由用户指定的传入程序中的实参,而且参数是字符串类型,故E也是不正确的。

36。C

数组是引用类型,它的元素相当于类的成员变量,而成员变量是能够被隐式初始化的,因此数组的元素也能够被隐式初始化,int类型被隐式初始化为0,因此选择C。

37。A

自动变量不能被static修饰,如果将static关键字去掉,答案选择C。

38。014

将十进制化成八进制后在数字前加“0”。

39。0x7

十六进制数用在数字前加“0x”表示。

40。B

字符类型是用16位UniCode表示的。

41。B

整型数的取值范围是-2n~2n-1,n表示各种类型的表示位数。

42。B

JAVA中的参数传递全是值传递,所不同的是,对于引用类型来说,变量内部存放的是对象内存空间的引用,因此引用类型在进行参数传递时,是将引用拷贝给形式参数。因此在方法中绝不可能改变主调方法中引用变量的引用,可是可能改变主调方法中引用变量的某一属性(就象对ch[0]的改变一样)。

43。A

注意main()方法的参数数组是在程序运行时由系统创立的,大小已经固定了。选项C、D引用args[count]可能会导致数组指针越界异常。

44。B

请查阅类结构,并注意她们的继承关系。这主要考查流链知识点。

45。B

控件TextArea如题中的构造方法的后两个参数分别表示行、列。注意题中的关键词语“prorortionalpitch”,因此不一定是5列字,但一定是5行。

46。B

“5”表示能够选择的项目数显示为5行,但能够拖动滑块观察其它选项。“true”表示能够多选。

47。this(a,b);

注意教材中提到使用this方法能够简化构造函数的编写。此时它必须放在构造函数的第一句。

48。C、D、E

JAVA语言中声明数组时,方括号与变量的位置关系非常灵活。

49。A、E

Java中大小写敏感,注意文件名是Fred.java,故B错误;Java中不支持多继承,故C错误;Java中与文件名相同的类名的访问权限一定是public,故D错误。

50。C

请查阅关于访问权限的表格说明。51.WhichcorrectlycreateanarrayoffiveemptyStrings?A.Stringa[]=newString[5];for(inti=0;i<5;a[i++]=””);B.Stringa[]={“”,””,””,””,””};C.Stringa[5];D.String[5]a;E.String[]a=newString[5];for(inti=0;i<5;a[i++]=null);52.WhichcannotbeaddedtoaContainer?A.anAppletB.aComponentC.aContainerD.aMenuComponentE.apanel53.WhichisthereturnvalueofEventlistener?smethod?A.StringB.AWTEventC.voidD.int54.IfweimplementsMouseListener,whichiscorrectedargumentofitsmethod?(shortanswer)55.Usetheoperator“>>”and“>>>”.Whichstatementistrue?A.10100000000000000000000000000000>>4give00001010000000000000000000000000B.10100000000000000000000000000000>>4give11111010000000000000000000000000C.10100000000000000000000000000000>>>4give00001010000000000000000000000000D.10100000000000000000000000000000>>>4give1111101000000000000000000000000056.Givefollowingfragment.Outer:for(inti=0;i<3;i++)inner:for(intj=0;j<3;j++){If(j>1)breakouter;System.out.println(j+”and”+i);}Whichwillbeoutput?A.0and0B.0and1C.0and2D.0and3E.1and0F.1and1G.1and2H.1and3I.2and0J.2and1K.2and2L.2and357.Examinethefollowingcodewhichincludesaninnerclass:publicfinalclassTest4implementsA{classInner{voidtest(){if(Test4.this.flag);{sample();}}privatebooleanflag=false;}publicvoidsample(){System.out.println(“Sample”);}publicTest4(){(newInner()).test();}publicstaticvoidmain(Stringargs[]){pclass="line-height">续:Java程序员认证模拟题及分析(1)和(2)51.WhichcorrectlycreateanarrayoffiveemptyStrings?A.Stringa[]=newString[5];for(inti=0;i<5;a[i++]=””);B.Stringa[]={“”,””,””,””,””};C.Stringa[5];D.String[5]a;E.String[]a=newString[5];for(inti=0;i<5;a[i++]=null);52.WhichcannotbeaddedtoaContainer?A.anAppletB.aComponentC.aContainerD.aMenuComponentE.apanel53.WhichisthereturnvalueofEventlistener?smethod?A.StringB.AWTEventC.voidD.int54.IfweimplementsMouseListener,whichiscorrectedargumentofitsmethod?(shortanswer)55.Usetheoperator“>>”and“>>>”.Whichstatementistrue?A.10100000000000000000000000000000>>4give00001010000000000000000000000000B.10100000000000000000000000000000>>4give11111010000000000000000000000000C.10100000000000000000000000000000>>>4give00001010000000000000000000000000D.10100000000000000000000000000000>>>4give1111101000000000000000000000000056.Givefollowingfragment.Outer:for(inti=0;i<3;i++)inner:for(intj=0;j<3;j++){If(j>1)breakouter;System.out.println(j+”and”+i);}Whichwillbeoutput?A.0and0B.0and1C.0and2D.0and3E.1and0F.1and1G.1and2H.1and3I.2and0J.2and1K.2and2L.2and357.Examinethefollowingcodewhichincludesaninnerclass:publicfinalclassTest4implementsA{classInner{voidtest(){if(Test4.this.flag);{sample();}}privatebooleanflag=false;}publicvoidsample(){System.out.println(“Sample”);}publicTest4(){(newInner()).test();}publicstaticvoidmain(Stringargs[]){newTest4();}}Whatistheresult:A.Printout“Sample”B.Programproducesnooutputbuttermiantescorrectly.C.Programdoesnotterminate.D.Theprogramwillnotcompile58.Whatiswrittentothestandardoutputgiventhefollowingstatement:System.out.println(4|7);Selecttherightanswer:A.4B.5C.6D.7E.059.Looktheinheritancerelation:person|----------------||manwomanInasourceofjavahavethefollowingline:personp=newman();Whatstatementarecorrected?A.Theexpressionisillegal.B.Compilecorrectedbutrunningwrong.C.Theexpressionislegal.D.Willconstructaperson?sobject.60.Looktheinheritancerelation:person|----------------||manwomanInasourceofjavahavethefollowingline:womanw=newman():Whatstatementarecorrected?A.Theexpressionisillegal.B.Compilecorrectedbutrunningwrong.C.Theexpressionislegal.D.Willconstructawomanobject.61.WhichcanNOTbeusedindeclaringordeclaringandinitializinganautomatic(methodlocal)variable?A.finalB.staticC.expressionsD.Constantsofnon-primitivetypeE.initializedarrays(suchas“{“Hello”,”Goodbye”}”).62.Giventhefollowingincompletemethod:1)publicvoidmethod(){2)3)if(someTestFails()){4)5)}6)7)}YouwanttomakethismethodthrowanIOExceptionif,andonlyif,themethodsomeTestFails()returnsavalueoftrue.Whichchangesachievethis?A.Addatline2:IOExceptione;B.Addatline4:throwe;C.Addatline4:thrownewIOException();D.Addatline6:thrownewIOException();E.ModifythemethoddeclarationtoindicatethatanobjectoftypeExceptionmightbethrown.63.Giventhefollowingdefinition:Strings=null;WhichcodefragmentscauseanobjectoftypeNullPointerExceptiontobethrown?A.if((s!=null)&(s.length()>0))B.if((s!=null)&&(s.length()>0))C.if((s==null)|(s.length()==0))D.if((s==null)||(s.length()==0))64.Thefollowingisaprogram1)classExsuper{2)Stringname;3)Stringnick_name;4)5)publicExSuper(Strings,Stringt){6)name=s;7)nick_name=t;8)}9)10)publicstringtoString(){11)returnname;12)}13)}14)15)publicclassExampleextendsExSuper{16)17)publicExample(Strings,Stringt){18)super(s,t);19)}20)21)publicStringtoString(){22)returnname+”a.k.a”+nick_name;23)}24)25)publicstaticvoidmain(Stringargs[]){26)ExSupera=newExSuper(“First”,”1st”);27)ExSuperb=newExample(“Second”,”2nd”);28)29)System.out.println(“ais”+a.toString());30)System.out.println(“bis”+b.toString());31)}32)}Whathappenswhentheuserattemptstocompileandrunthisprogram?A.ACompilererroroccursatline21B.AnobjectoftypeClassCastExceptionisthrownatline27C.Thefollowingoutput:aisFirstbissecondD.T

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论