第1页共34页面向对象编程基础习题及答案PartI.ChoiceQuestions(1ptforeachquestion).1.Toaddatobandstoreresultinb,youwrite(Note:Javaiscase-sensitive)A.b+=a;B.a=b+a;C.b=A+b;D.a+=b;2.TodeclareaconstantPI,youwriteA.finalstaticPI=3.14159;B.finalfloatPI=3.14159;C.staticdoublePI=3.14159;D.finaldoublePI=3.14159;3.Toimprovereadabilityandmaintainability,youshoulddeclare_________insteadofusingliteralvaluessuchas3.14159.A.variablesB.methodsC.constantsD.classes4.Todeclareanintvariablexwithinitialvalue200,youwriteA.intx=200L;B.intx=200l;C.intx=200;D.intx=200.0;5.Toassignadoublevariabledtoanintvariablex,youwriteA.x=(long)dB.x=(int)d;C.x=d;D.x=(float)d;6.InJava,thewordtrueis________.A.aJavakeywordB.aBooleanliteralC.sameasvalue1D.sameasvalue07.WhichoftheBooleanexpressionsbelowhasincorrectsyntax?A.(true)&&(34)B.!(x0)&&(x0)C.(x0)||(x0)D.(x!=0)||(x=0)8.Whichofthefollowingisthecorrectexpressionthatevaluatestotrueifthenumberxisbetween1and100orthenumberisnegative?A.1x100&&x0第2页共34页B.((x100)&&(x1))||(x0)C.((x100)&&(x1))&&(x0)D.(1x100)||(x0)9.Whichofthefollowingisthecorrectexpressionofcharactera?A.'a'B.aC.'\000a'D.Noneoftheabove.10.Whichofthefollowingstatementprintssmith\exam1\test.txt?A.System.out.println(smith\exam1\test.txt);B.System.out.println(smith\\exam1\\test.txt);C.System.out.println(smith\exam1\test.txt);D.System.out.println(smith\exam1\test.txt);11.Supposeiisaninttypevariable.WhichofthefollowingstatementsdisplaythecharacterwhoseUnicodeisstoredinvariablei?A.System.out.println(i);B.System.out.println((char)i);C.System.out.println((int)i);D.System.out.println(i+);12.TheUnicodeof'a'is97.WhatistheUnicodefor'c'?A.96B.97C.98D.9913.Whichofthefollowingisaconstant,accordingtoJavanamingconventions?A.MAX_VALUEB.TestC.readD.ReadInt14.Whichofthefollowingassignmentstatementsisillegal?A.floatf=-34;B.intt=23;C.shorts=10;D.floatf=34.0;15.AJavastatementendswitha__________.A.comma(,)B.semicolon(;)C.period(.)D.closingbrace16.TheassignmentoperatorinJavais__________.A.:=B.=C.==第3页共34页D.-17.Supposemandrareintegers.WhatisthecorrectJavaexpressionform/r^2toobtainafloatingpointresultvalue?(r^2denotesrraisedtothepowerof2).A.m/r*rB.m/(r*r)C.1.0*m/r*rD.1.0*m/(r*r)18.Whichofthesedatatypesrequirestheleastamountofmemory?A.floatB.doubleC.shortD.byte19.Whichofthefollowingoperatorshasthehighestprecedence?A.castingB.+C.*D./20.Anintvariablecanhold__________.A.'x'B.93C.98.3D.trueE.aandb21.Whichofthefollowingassignmentstatementsiscorrecttoassigncharacter5toc?A.charc='5';B.charc=5;C.charc=5;D.charc=344;22.NotethattheUnicodeforcharacterAis65.TheexpressionA+1evaluatesto________.A.66B.BC.A1D.Illegalexpression23.ThenotequalcomparisonoperatorinJavais__________.A.B.!=C.!==D.^=24.Ifyouattempttoaddanint,abyte,along,andadouble,theresultwillbea__________value.A.byteB.int;C.long;第4页共34页D.double;25.Whatisthevalueof(double)5/2?A.2;B.2.5;C.3;D.2.0;26.Whatisthevalueof(double)(5/2)?A.2;B.2.5;C.3;D.2.0;27.Analyzethefollowingcode.publicclassTest{publicstaticvoidmain(String[]args){intmonth=09;System.out.println(monthis+month);}}A.Theprogramdisplaysmonthis09B.Theprogramdisplaysmonthis9C.Theprogramdisplaysmonthis9.0D.Theprogramhasasyntaxerror,because09isanincorrectliteralvalue.28.Toassignadoublevariabledtoafloatvariablex,youwriteA.x=(long)dB.x=(int)d;C.x=d;D.x=(float)d;29.whatisydisplayedinthefollowingcode?publicclassTest1{publicstaticvoidmain(String[]args){intx=1;inty=x=x+1;System.out.println(yis+y);}}A.yis0.B.yis1becausexisassignedtoyfirst.C.yis2becausex+1isassignedtoxandthenxisassigned第5页共34页toy.D.Theprogramhasasyntaxerrorsincexisredeclaredinthestatementinty=x=x+1.30.Ifaprogramcompilesfine,butitterminatesabnormallyatruntime,thentheprogramsuffers__________.A.asyntaxerrorB.aruntimeerrorC.alogicerror31.Supposex=0andy=0whatisxafterevaluatingtheexpression(y0)&(1x++).A.0B.-1C.132.Supposex=0andy=0whatisxafterevaluatingtheexpression(y0)&&(1x++).A.0B.-1C.133.SupposeyoudefineaJavaclassasfollows:publicclassTest{}Inordertocompilethisclass,theclassshouldbestoredinafilenamedA.Test.classB.Test.docC.Test.txtD.Test.javaE.Anynamewithextension.java34.ThecommandtocompileaclassinthefileTest.javaisA.javaTestB.javaTest.javaC.javacTest.javaD.javacTestE.JAVACTest.java35.WhichJDKcommandiscorrecttorunaJavaapplicationinByteCode.class?A.javaByteCodeB.javaByteCode.classC.javacByteCode.javaD.javacByteCodeE.JAVACByteCode36.Whatis1%2?A.0第6页共34页B.1C.237.WhatisWelcome+1+1*2?A.Welcome11*2B.Welcome4C.Welcome12D.Welcome338.Whatistheprintoutofthefollowingcode:doublex=10.1;inty=(int)x;System.out.println(xis+x+andyis+y);A.xis10andyis10B.xis10.0andyis10.0C.xis11andyis11D.xis10.1andyis10E.xis10.1andyis10.039.Whichofthefollowingcodedisplaystheareaofacircleiftheradiusispositive.A.if(radius!=0)System.out.println(radius*radius*Math.PI);B.if(radius=0)System.out.println(radius*radius*Math.PI);C.if(radius0)System.out.println(radius*radius*Math.PI);D.if(radius=0)System.out.println(radius*radius*Math.PI);40.Supposex=1,y=-1,andz=1.Whatistheprintoutofthefollowingstatement?if(x0)if(y0)System.out.println(x0andy0);elseif(z0)S