java考试选择题英文版.docx

上传人:b****6 文档编号:3326658 上传时间:2022-11-21 格式:DOCX 页数:25 大小:21.69KB
下载 相关 举报
java考试选择题英文版.docx_第1页
第1页 / 共25页
java考试选择题英文版.docx_第2页
第2页 / 共25页
java考试选择题英文版.docx_第3页
第3页 / 共25页
java考试选择题英文版.docx_第4页
第4页 / 共25页
java考试选择题英文版.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

java考试选择题英文版.docx

《java考试选择题英文版.docx》由会员分享,可在线阅读,更多相关《java考试选择题英文版.docx(25页珍藏版)》请在冰豆网上搜索。

java考试选择题英文版.docx

java考试选择题英文版

Readthequestionscarefully

Ihavetriedtomakethequestionsunambiguous(themeaningshouldbeobvious),butmakesureyouhavereadwhatIhavewrittennotwhatyouthinkImighthavewritten.Thusifitsays"Classescanbedeclaredwiththeprivatemodifier",itmeansItispossibletodeclareaclasswiththeprivatemodifierandnotthatallclassesinallsituationscanbedeclaredasprivate.EachquestionmayhaveoneormorecorrectAnswers.

Questions

Question1)

Whichofthefollowinglineswillcompilewithoutwarningorerror.

1)floatf=1.3;

2)charc="a";

3)byteb=257;

4)booleanb=null;

5)inti=10;

Question2)

Whatwillhappenifyoutrytocompileandrunthefollowingcode

publicclassMyClass{

publicstaticvoidmain(Stringarguments[]){

amethod(arguments);

}

publicvoidamethod(String[]arguments){

System.out.println(arguments);

System.out.println(arguments[1]);

}

}

1)errorCan'tmakestaticreferencetovoidamethod.

2)errormethodmainnotcorrect

3)errorarraymustincludeparameter

4)amethodmustbedeclaredwithString

Becausemainisdefinedasstaticyouneedtocreateaninstanceoftheclassinordertocallanynon-staticmethods.

--------------------------------------------------------------------------------

Question3)

Whichofthefollowingwillcompilewithouterror

要先出现package

1)importjava.awt.*;

packageMypackage;

classMyclass{}

2)packageMyPackage;

importjava.awt.*;

classMyClass{}

3)/*Thisisacomment*/

packageMyPackage;

importjava.awt.*;

classMyClass{}

--------------------------------------------------------------------------------

Question4)

Abytecanbeofwhatsize

1)-128to127

2)(-2power8)-1to2power8

3)-255to256

4)dependsontheparticularimplementationoftheJavaVirtualmachine

--------------------------------------------------------------------------------

Question5)

Whatwillbeprintedoutifthiscodeisrunwiththefollowingcommandline?

Javamyproggoodmorning;

publicclassmyprog{

publicstaticvoidmain(Stringargv[])

{

System.out.println(argv[2]);

}

}

1)myprog

2)good

3)morning

4)Exceptionraised:

"java.lang.ArrayIndexOutOfBoundsException:

2"

--------------------------------------------------------------------------------

Question6)

Whichofthefollowingarekeywordsorreserved(预定义)wordsinJava?

1)if

2)then

3)goto

4)while

5)case

--------------------------------------------------------------------------------

Question7)

Whichofthefollowingarelegalidentifiers(标识符)

1)2variable

2)variable2

3)_whatavariable

4)_3_

5)$anothervar

6)#myvar

--------------------------------------------------------------------------------

Question8)

Whatwillhappenwhenyoucompileandrunthefollowingcode?

publicclassMyClass{

staticinti;

publicstaticvoidmain(Stringargv[]){

System.out.println(i);

}

}

局部变量(在函数内部)必须先初始化,类级别的可以不初始化

Classlevelvariablesarealwaysinitialisedtodefaultvalues.Inthecaseofanintthiswillbe0.Methodlevelvariablesarenotgivendefaultvaluesandifyouattempttouseonebeforeithasbeeninitialiseditwillcausethe

ErrorVariableimaynothavebeeninitialized

1)ErrorVariableimaynothavebeeninitialized

2)null

3)1

4)0

--------------------------------------------------------------------------------

Question9)

Whatwillhappenifyoutrytocompileandrunthefollowingcode?

publicclassQ{

publicstaticvoidmain(Stringargv[]){

intanar[]=newint[]{1,2,3};

System.out.println(anar[1]);

}

}

1)1

2)Erroranarisreferencedbeforeitisinitialized

3)2

4)Error:

sizeofarraymustbedefined

--------------------------------------------------------------------------------

Question10)

Whatwillhappenifyoutrytocompileandrunthefollowingcode?

publicclassQ{

publicstaticvoidmain(Stringargv[]){

intanar[]=newint[5];

System.out.println(anar[0]);

}

}

1)Error:

anarisreferencedbeforeitisinitialized

2)null

3)0

4)5

--------------------------------------------------------------------------------

 

Question11)

Whatwillbetheresultofattemptingtocompileandrunthefollowingcode?

abstractclassMineBase{

abstractvoidamethod();

staticinti;

}

publicclassMineextendsMineBase{

publicstaticvoidmain(Stringargv[]){

int[]ar=newint[5];

for(i=0;i

System.out.println(ar[i]);

}

}

Anyclassderivedfromanabstractclassmusteitherdefinealloftheabstractmethodsorbedeclaredabstractitself.

1)asequenceof50'swillbeprinted

2)Error:

arisusedbeforeitisinitialized

3)ErrorMinemustbedeclaredabstract

4)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)one

2)one,default

3)one,two,default

4)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)default

2)default,zero

3)errordefaultclausenotdefined

4)nooutputdisplayed

--------------------------------------------------------------------------------

Question14)

Whichofthefollowinglinesofcodewillcompilewithouterror

1)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.println("OK");

4)inti=1;

intj=2;i

f(i==1&|j==2)System.out.println("OK");

--------------------------------------------------------------------------------

Question15)

Whatwillbeoutputifyoutrytocompileandrunthefollowingcode,butthereis

nofilecalledHello.txtinthecurrentdirectory?

.

importjava.io.*;

publicclassMine{

publicstaticvoidmain(Stringargv[]){

Minem=newMine();

System.out.println(m.amethod());

}

publicintamethod(){

try{

FileInputStreamdis=newFileInputStream("Hello.txt");

}catch(FileNotFoundExceptionfne){

System.out.println("Nosuchfilefound");

return-1;

}catch(IOExceptionioe){}

finally{

System.out.println("Doingfinally");

}

return0;

}

}

1)Nosuchfilefound

2Nosuchfilefound,-1

3)Nosuchfilefound,Doingfinally,-1

4)0

--------------------------------------------------------------------------------

Question16)

Whichofthefollowingstatementsaretrue?

1)Methodscannotbeoverridentobemoreprivate

2)staticmethodscannotbeoverloaded

Staticmethodscannotbeoverridenbuttheycanbeoverloaded

3)privatemethodscannotbeoverloaded

4)Anoverloadedmethodcannotthrowexceptionsnotcheckedinthebaseclass

 

--------------------------------------------------------------------------------

Question17)

Whatwillhappenifyouattempttocompileandrunthefollowingcode?

classBase{}

classSubextendsBase{}

classSub2extendsBase{}

publicclassCEx{

publicstaticvoidmain(Stringargv[]){

Baseb=newBase();

Subs=(Sub)b;

}

}

1)Compileandrunwithouterror

2)CompiletimeException

3)RuntimeException

--------------------------------------------------------------------------------

Question18)

Whichofthefollowingstatementsaretrue?

1)System.out.println(-1>>>2);willoutputaresultlargerthan10无符号右移

2)System.out.println(-1>>2);willoutputapositivenumber输出-1

3)System.out.println(2>>1);willoutputthenumber1

4)System.out.println(1<<<2);willoutputthenumber4

--------------------------------------------------------------------------------

Question19)

Whatwillhappenwhenyouattempttocompileandrunthefollowingcode?

publicclassTuxextendsThread{

staticStringsName="vandeleur";

publicstaticvoidmain(Stringargv[]){

Tuxt=newTux();

t.piggy(sName);

System.out.println(sName);

}

publicvoidpiggy(StringsName){

sName=sName+"wiggy";

start();

}

publicvoidrun(){

for(inti=0;i<4;i++){

sName=sName+""+i;

}

}

}

1)Compiletimeerror

2)Compilationandoutputof"vandeleurwiggy"

3)Compilationandoutputof"vandeleurwiggy0123"

4)Compilationandoutputofeither"vandeleur","vandeleur0","vandeleur01""vandaleur012"or"vandaleur0123"

--------------------------------------------------------------------------------

Question20)

Whatwillbedisplayedwhenyouattempttocompileandrunthefollowingcode

//Codestart

importjava.awt.*;

publicclassButtextendsFrame{

publicstaticvoidmain(Stringargv[]){

ButtMyBut=newButt();

}

Butt(){

ButtonHelloBut=newButton("Hello");

ButtonByeBut=newButton("Bye");

add(HelloBut);

add(ByeBut);

setSize(300,300);

setVisible(true);}}//Codeend

1)Twobuttonssidebysideoccupyingalloftheframe,HelloontheleftandByeon

theright

2)OnebuttonoccupyingtheentireframesayingHello

3)OnebuttonoccupyingtheentireframesayingBye

4)TwobuttonsatthetopoftheframeonesayingHellotheothersayingBye

--------------------------------------------------------------------------------

Question21)

Whatwillbeoutputbythefollowingcode?

publicclassMyFor{

publicstaticvoidmain(Stringargv[]){

inti

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 中考

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1