Java.docx
- 文档编号:7655432
- 上传时间:2023-01-25
- 格式:DOCX
- 页数:16
- 大小:19.43KB
Java.docx
《Java.docx》由会员分享,可在线阅读,更多相关《Java.docx(16页珍藏版)》请在冰豆网上搜索。
Java
1.2Whichdeclarationofthemainmethodbelowwouldallowaclasstobestartedasastandaloneprogram.Selecttheonecorrectanswer.
A.publicstaticintmain(charargs[])
B.publicstaticvoidmain(Stringargs[])
C.publicstaticvoidMAIN(Stringargs[])
D.publicstaticvoidmain(Stringargs)
E.publicstaticvoidmain(charargs[])B
2.Whatallgetsprintedwhenthefollowingcodeiscompiledandrun?
Selectthethreecorrectanswers.
publicclassxyz{
publicstaticvoidmain(Stringargs[]){
for(inti=0;i<2;i++){
for(intj=2;j>=0;j--){
if(i==j)break;
System.out.println("i="+i+"j="+j);
}
}
}
}
0,2;0,1;1,2;
A.i=0j=0
B.i=0j=1
C.i=0j=2
D.i=1j=0
E.i=1j=1
F.i=1j=2
G.i=2j=0
H.i=2j=1
I.i=2j=2BCF
3.Whatgetsprintedwhenthefollowingcodeiscompiledandrunwiththefollowingcommand-
javatest2
Selecttheonecorrectanswer.
publicclasstest{
publicstaticvoidmain(Stringargs[]){
IntegerintObj=Integer.valueOf(args[args.length-1]);
inti=intObj.intValue();
if(args.length>1)
System.out.println(i);
if(args.length>0)
System.out.println(i-1);
else
System.out.println(i-2);
}
}
4.
A.test
B.test-1
C.0
D.1
E.2B
5.InJavatechnologywhatexpressioncanbeusedtorepresentnumberofelementsinanarraynamedarr?
arr.length
6.Howwouldthenumber5berepresentedinhexusingup-tofourcharacters.Ox05十六进制中的表示为0X--,八进制为0--
7.WhichofthefollowingisaJavakeyword.Selectthefourcorrectanswers.
A.extern
B.synchronized
C.volatile
D.friend
E.friendly
F.transient
G.this
H.thenBCFG
8.Isthefollowingstatementtrueorfalse.Theconstructorofaclassmustnothaveareturntype.
A.true
B.false
9.WhatisthenumberofbytesusedbyJavaprimitivelong.Selecttheonecorrectanswer.
A.Thenumberofbytesiscompilerdependent.
B.2
C.4
D.8
E.64E
10.Whatisreturnedwhenthemethodsubstring(2,4)isinvokedonthestring"example"?
IncludetheanswerinquotesastheresultisoftypeString.am第二个开始持续2个
11.Whichofthefollowingiscorrect?
Selectthetwocorrectanswers.
A.ThenativekeywordindicatesthatthemethodisimplementedinanotherlanguagelikeC/C++.
B.TheonlystatementsthatcanappearbeforeanimportstatementinaJavafilearecomments.
C.Themethoddefinitionsinsideinterfacesarepublicandabstract.Theycannotbeprivateorprotected.
D.Aclassconstructormayhavepublicorprotectedkeywordbeforethem,nothingelse.AD
12.Whatistheresultofevaluatingtheexpression14^23.Selecttheonecorrectanswer.
A.25异或01110跟1011111001
B.37
C.6
D.31
E.17
F.9
G.24A
13.Whichofthefollowingaretrue.Selecttheonecorrectanswers.
A.&&operatorisusedforshort-circuitedlogicalAND.
B.~operatoristhebit-wiseXORoperator.
C.|operatorisusedtoperformbitwiseORandalsoshort-circuitedlogicalOR.
D.TheunsignedrightshiftoperatorinJavais>>.A
14.Nametheaccessmodifierwhichwhenusedwithamethod,makesitavailabletoalltheclassesinthesamepackageandtoallthesubclassesoftheclass.public
15.Whichofthefollowingistrue.Selectthetwocorrectanswers.
A.Aclassthatisabstractmaynotbeinstantiated.
B.Thefinalkeywordindicatesthatthebodyofamethodistobefoundelsewhere.Thecodeiswritteninnon-Javalanguage,typicallyinC/C++.
C.Astaticvariableindicatesthereisonlyonecopyofthatvariable.
D.Amethoddefinedasprivateindicatesthatitisaccessibletoallotherclassesinthesamepackage.AC
16.Whatallgetsprintedwhenthefollowingprogramiscompiledandrun.Selectthetwocorrectanswers.
publicclasstest{
publicstaticvoidmain(Stringargs[]){
inti,j=1;
i=(j>1)?
2:
1;i=1
switch(i){
case0:
System.out.println(0);break;
case1:
System.out.println
(1);
case2:
System.out.println
(2);break;
case3:
System.out.println(3);break;
}
}
}
17.
A.0
B.1
C.2
D.3BC
18.Whatallgetsprintedwhenthefollowingprogramiscompiledandrun.Selecttheonecorrectanswer.
publicclasstest{
publicstaticvoidmain(Stringargs[]){
inti=0,j=2;
do{
i=++i;
j--;
}while(j>0);
System.out.println(i);
}
}
A.0
B.1
C.2
D.Theprogramdoesnotcompilebecauseofstatement"i=++i;"C
19.Whatallgetsprintedwhenthefollowinggetscompiledandrun.Selectthethreecorrectanswers.
publicclasstest{
publicstaticvoidmain(Stringargs[]){
inti=1,j=1;
try{
i++;
j--;
if(i/j>1)
i++;
}
catch(ArithmeticExceptione){
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsExceptione){
System.out.println
(1);
}
catch(Exceptione){
System.out.println
(2);
}
finally{
System.out.println(3);
}
System.out.println(4);
}
}
A.0
B.1
C.2
D.3
E.4BDE
20.Whatallgetsprintedwhenthefollowinggetscompiledandrun.Selectthetwocorrectanswers.
publicclasstest{
publicstaticvoidmain(Stringargs[]){
inti=1,j=1;
try{
i++;
j--;
if(i==j)
i++;
}
catch(ArithmeticExceptione){
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsExceptione){
System.out.println
(1);
}
catch(Exceptione){
System.out.println
(2);
}
finally{
System.out.println(3);
}
System.out.println(4);
}
}
21.
A.0
B.1
C.2
D.3
E.4DE
22.Whatallgetsprintedwhenthefollowinggetscompiledandrun.Selectthetwocorrectanswers.
publicclasstest{
publicstaticvoidmain(Stringargs[]){
Strings1="abc";
Strings2="abc";
if(s1==s2)
System.out.println
(1);
else
System.out.println
(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
23.
A.1
B.2
C.3
D.4AC
24.Whatallgetsprintedwhenthefollowinggetscompiledandrun.Selectthetwocorrectanswers.
publicclasstest{
publicstaticvoidmain(Stringargs[]){
Strings1="abc";
Strings2=newString("abc");
if(s1==s2)
System.out.println
(1);
else
System.out.println
(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
A.1
B.2
C.3
D.4AC
25.Whichofthefollowingarelegalarraydeclarations.Selectthethreecorrectanswers.
A.inti[5][];
B.inti[][];
C.int[]i[];
D.inti[5][5];
E.int[][]a;BCE
26.Whatistherangeofvaluesthatcanbespecifiedforanint.Selecttheonecorrectanswer.
A.Therangeofvaluesiscompilerdependent.
B.-231to231-1
C.-231-1to231
D.-215to215-1
E.-215-1to215B
27.Howcanyouensurethatthememoryallocatedbyanobjectisfreed.Selecttheonecorrectanswer.
A.Byinvokingthefreemethodontheobject.
B.Bycallingsystem.gc()method.
C.Bysettingallreferencestotheobjecttonewvalues(saynull).
D.Garbagecollectioncannotbeforced.TheprogrammercannotforcetheJVMtofreethememoryusedbyanobject.D
28.Whatgetsprintedwhenthefollowingcodeiscompiledandrun.Selecttheonecorrectanswer.
publicclasstest{
publicstaticvoidmain(Stringargs[]){
inti=1;
do{
i--;
}while(i>2);
System.out.println(i);
}
}
29.
A.0
B.1
C.2
D.-1A
30.WhichoftheseisalegaldefinitionofamethodnamedmassumingitthrowsIOException,andreturnsvoid.Alsoassumethatthemethoddoesnottakeanyarguments.Selecttheonecorrectanswer.
A.voidm()throwsIOException{}
B.voidm()throwIOException{}
C.voidm(void)throwsIOException{}
D.m()throwsIOException{}
E.voidm(){}throwsIOExceptionA
31.WhichofthefollowingarelegalidentifiernamesinJava.Selectthetwocorrectanswers.
A.%abcd
B.$abcd
C.1abcd
D.package
E._a_long_nameAC
32.Atwhatstageinthefollowingmethoddoestheobjectinitiallyreferencedbysbecomesavailableforgarbagecollection.Selecttheonecorrectanswer.
voidmethodX(){
Stringr=newString("abc");
Strings=newString("abc");
r=r+1;//1
r=null;//2
s=s+r;//3
}//4
A.Beforestatementlabeled1
B.Beforestatementlabeled2
C.Beforestatementlabeled3
D.Beforestatementlabeled4
E.Never.C
33.Strings=newString("xyz");
Assumingtheabovedeclaration,whichofthefollowingstatementswouldcompile.Selecttheonecorrectanswer.
A.s=2*s;
B.inti=s[0];
C.s=s+s;
D.s=s>>2;
E.Noneoftheabove.C
34.WhichofthefollowingstatementsrelatedtoGarbageCollectionarecorrect.Selectthetwocorrectanswers.
A.Itispossibleforaprogramtofreememoryatagiventime.
B.GarbageCollectionfeatureofJavaensuresthattheprogramneverrunsoutofmemory.
C.ItispossibleforaprogramtomakeanobjectavailableforGarbageCollection.
D.Thefinalizemethodofanobjectisinvokedbeforegarbagecollectionisperformedontheobject.CD
35.Ifabaseclasshasamethoddefinedas
voidmethod(){}
Whichofthefollowingarelegalprototypesinaderivedclassofthisclass.Selectthetwocorrectanswers.
A.voidmethod(){}
B.intmethod(){return0;}
C.voidmethod(inti){}
D.privatevoidmethod(){}A
36.Inwhichallcasesdoesanexceptiongetsgenerated.Selectthetwocorrectanswers.
inti=0,j=1;
A.if((i==0)||(j/i==1))
B.if((i==0)|(j/i==1))
C.if((i!
=0)&&(j/i==1))
D.if((i!
=0)&(j/i==1))D
37.Whichofthefollowingstatementsaretrue.Selectthetwocorrectanswers.
A.ThewaitmethoddefinedintheThreadclass,canbeusedtoconvertathreadfromRunningstatetoWaitingstate.
B.Thewait(),notify(),andnotifyAll()methodsmustbeexecutedinsynchronizedcod
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java