您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 能源与动力工程 > java考试选择题英文版
ReadthequestionscarefullyIhavetriedtomakethequestionsunambiguous(themeaningshouldbeobvious),butmakesureyouhavereadwhatIhavewrittennotwhatyouthinkImighthavewritten.ThusifitsaysClassescanbedeclaredwiththeprivatemodifier,itmeansItispossibletodeclareaclasswiththeprivatemodifierandnotthatallclassesinallsituationscanbedeclaredasprivate.EachquestionmayhaveoneormorecorrectAnswers.QuestionsQuestion1)Whichofthefollowinglineswillcompilewithoutwarningorerror.1)floatf=1.3;2)charc=a;3)byteb=257;4)booleanb=null;5)inti=10;Question2)WhatwillhappenifyoutrytocompileandrunthefollowingcodepublicclassMyClass{publicstaticvoidmain(Stringarguments[]){amethod(arguments);}publicvoidamethod(String[]arguments){System.out.println(arguments);System.out.println(arguments[1]);}}1)errorCan'tmakestaticreferencetovoidamethod.2)errormethodmainnotcorrect3)errorarraymustincludeparameter4)amethodmustbedeclaredwithStringBecausemainisdefinedasstaticyouneedtocreateaninstanceoftheclassinordertocallanynon-staticmethods.--------------------------------------------------------------------------------Question3)Whichofthefollowingwillcompilewithouterror要先出现package1)importjava.awt.*;packageMypackage;classMyclass{}2)packageMyPackage;importjava.awt.*;classMyClass{}3)/*Thisisacomment*/packageMyPackage;importjava.awt.*;classMyClass{}--------------------------------------------------------------------------------Question4)Abytecanbeofwhatsize1)-128to1272)(-2power8)-1to2power83)-255to2564)dependsontheparticularimplementationoftheJavaVirtualmachine--------------------------------------------------------------------------------Question5)Whatwillbeprintedoutifthiscodeisrunwiththefollowingcommandline?Javamyproggoodmorning;publicclassmyprog{publicstaticvoidmain(Stringargv[]){System.out.println(argv[2]);}}1)myprog2)good3)morning4)Exceptionraised:java.lang.ArrayIndexOutOfBoundsException:2--------------------------------------------------------------------------------Question6)Whichofthefollowingarekeywordsorreserved(预定义)wordsinJava?1)if2)then3)goto4)while5)case--------------------------------------------------------------------------------Question7)Whichofthefollowingarelegalidentifiers(标识符)1)2variable2)variable23)_whatavariable4)_3_5)$anothervar6)#myvar--------------------------------------------------------------------------------Question8)Whatwillhappenwhenyoucompileandrunthefollowingcode?publicclassMyClass{staticinti;publicstaticvoidmain(Stringargv[]){System.out.println(i);}}局部变量(在函数内部)必须先初始化,类级别的可以不初始化Classlevelvariablesarealwaysinitialisedtodefaultvalues.Inthecaseofanintthiswillbe0.MethodlevelvariablesarenotgivendefaultvaluesandifyouattempttouseonebeforeithasbeeninitialiseditwillcausetheErrorVariableimaynothavebeeninitialized1)ErrorVariableimaynothavebeeninitialized2)null3)14)0--------------------------------------------------------------------------------Question9)Whatwillhappenifyoutrytocompileandrunthefollowingcode?publicclassQ{publicstaticvoidmain(Stringargv[]){intanar[]=newint[]{1,2,3};System.out.println(anar[1]);}}1)12)Erroranarisreferencedbeforeitisinitialized3)24)Error:sizeofarraymustbedefined--------------------------------------------------------------------------------Question10)Whatwillhappenifyoutrytocompileandrunthefollowingcode?publicclassQ{publicstaticvoidmain(Stringargv[]){intanar[]=newint[5];System.out.println(anar[0]);}}1)Error:anarisreferencedbeforeitisinitialized2)null3)04)5--------------------------------------------------------------------------------Question11)Whatwillbetheresultofattemptingtocompileandrunthefollowingcode?abstractclassMineBase{abstractvoidamethod();staticinti;}publicclassMineextendsMineBase{publicstaticvoidmain(Stringargv[]){int[]ar=newint[5];for(i=0;iar.length;i++)System.out.println(ar[i]);}}Anyclassderivedfromanabstractclassmusteitherdefinealloftheabstractmethodsorbedeclaredabstractitself.1)asequenceof50'swillbeprinted2)Error:arisusedbeforeitisinitialized3)ErrorMinemustbedeclaredabstract4)IndexOutOfBoundesError--------------------------------------------------------------------------------Question12)Whatwillbeprintedoutifyouattempttocompileandrunthefollowingcode?inti=1;switch(i){case0:System.out.println(zero);break;case1:System.out.println(one);case2:System.out.println(two);default:System.out.println(default);}1)one2)one,default3)one,two,default4)default--------------------------------------------------------------------------------Question13)Whatwillbeprintedoutifyouattempttocompileandrunthefollowingcode?inti=9;switch(i){default:System.out.println(default);case0:System.out.println(zero);break;case1:System.out.println(one);case2:System.out.println(two);}1)default2)default,zero3)errordefaultclausenotdefined4)nooutputdisplayed--------------------------------------------------------------------------------Question14)Whichofthefollowinglinesofcodewillcompilewithouterror1)inti=0;if(i){System.out.println(Hello);}2)booleanb=true;booleanb2=true;if(b==b2){System.out.println(Sotrue);}3)inti=1;intj=2;if(i==1||j==2)System.out.print
本文标题:java考试选择题英文版
链接地址:https://www.777doc.com/doc-4953439 .html