Java试题详解Word格式文档下载.docx

上传人:b****5 文档编号:18678091 上传时间:2022-12-31 格式:DOCX 页数:16 大小:18.85KB
下载 相关 举报
Java试题详解Word格式文档下载.docx_第1页
第1页 / 共16页
Java试题详解Word格式文档下载.docx_第2页
第2页 / 共16页
Java试题详解Word格式文档下载.docx_第3页
第3页 / 共16页
Java试题详解Word格式文档下载.docx_第4页
第4页 / 共16页
Java试题详解Word格式文档下载.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

Java试题详解Word格式文档下载.docx

《Java试题详解Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《Java试题详解Word格式文档下载.docx(16页珍藏版)》请在冰豆网上搜索。

Java试题详解Word格式文档下载.docx

B(-2power8)-1to2power8

C-255to256

D不确定,根据的JVM的约定。

下面的代码运行以后,屏幕上会打印什么?

javamyproggoodmorning

publicclassmyprog{

publicstaticvoidmain(Stringargv[])

{

System.out.println(argv[2])

Amyprog

Bgood

Cmorning

DExceptionraised:

"

java.lang.ArrayIndexOutOfBoundsException:

2"

下面选项中那个即不是Java的关键字也不是保留字?

Aif

Bthen

Cgoto

Dwhile

Ecase

下面那个选项是合法的标示符:

A2variable

B%variable2

C$anothervar

D#myvar

编译和运行下面的代码会发生什么情况?

publicclassMyClass{

staticinti;

publicstaticvoidmain(Stringargv[]){

System.out.println(i);

A错误,变量i没有初始化

Bnull

C1

D0

publicclassQ{

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

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

A1

B3

C2

D编译错误,数组没有定义大小。

10 

intanar[]=newint[5];

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

A编译不能通过

C0

D5

11 

编译和运行下面的代码会发生什么情况?

abstractclassBase{

abstractpublicvoidmyfunc();

publicvoidanother(){

System.out.println("

Anothermethod"

);

}

publicclassAbsextendsBase{

publicstaticvoidmain(Stringargv[]){

Absa=newAbs();

a.amethod();

publicvoidmyfunc(){

MyFunc"

}

publicvoidamethod(){

myfunc();

A编译和运行成功,打印"

B编译出错,报告Base类没有抽象方法

C编译成功,运行时报告Base类没有抽象方法

D编译出错,Base类中的myfunc()没有内容

12 

运行下面的代码,会输出什么?

classValHold{

publicinti=10;

publicclassObParm{

ObParmo=newObParm();

o.amethod();

inti=99;

ValHoldv=newValHold();

v.i=30;

another(v,i);

System.out.print(v.i);

}//Endofamethod

publicvoidanother(ValHoldv,inti){

i=0;

v.i=20;

ValHoldvh=newValHold();

v=vh;

System.out.print(v.i);

System.out.print(i);

}//Endofanother

A10030

B20030

C209930

D10020

13 

publicclassMyMain{

publicstaticvoidmain(Stringargv){

Hellocruelworld"

A编译出错,main是保留字,不能用做类名

B编译和运行成功,打印"

C编译成功,运行时报告没有定义构造器

D编译成功,运行时报告main方法定义不正确。

14 

classBase{

Myfunc"

B编译出错,报告Base类不是抽象类

15 

publicfinalvoidamethod(){

amethod"

publicclassFinextendsBase{

Baseb=newBase();

b.amethod();

A编译出错,一个类中有final方法,这个类自己也应该声明为final类型

B编译出错,不能继承一个有final方法的类

C运行出错,Base类没有定义成final类型

D编译和运行成功,打印"

16 

privateclassBase{}

publicclassVis{

privateintiVal;

publicstaticvoidmain(Stringelephant[]){

A编译出错,Base类不能声明为private

B编译出错iVal不能声明为private

C编译出错,main方法定义不正确

D编译和运行成功

17 

在同一个目录下,编译和运行下面两个文件,会发生什么情况?

//FileP1.java

classP1{

voidafancymethod(){

Whatafancymethod"

//FileP2.java

publicclassP2extendsP1{

P2p2=newP2();

p2.afancymethod();

A编译都成功,P2类输出"

B都不能编译成功

C都能编译成功,P2类运行时出错

DP1编译成功,P2编译不能成功

18 

publicclassBgroundextendsThread{

Bgroundb=newBground();

b.run();

publicvoidstart(){

for(inti=0;

i<

10;

i++){

Valueofi="

+i);

A编译错误,Bground类中没有定义run方法

B编译成功,运行时出错,报告Bground类中没有定义run方法

C编译和运行成功,打印0至9

D编译和运行成功,没有输出

19 

publicclassHope{

Hopeh=newHope();

protectedHope(){

for(inti=0;

i++){

System.out.println(i);

A编译错误,构造器不能声明为protected类型

B运行时出错,构造器不能声明为protected类型

C编译和运行成功,输出0到10

D编译和运行成功,输出0到9

20 

publicclassMySwitch{

MySwitchms=newMySwitch();

ms.amethod();

publicvoidamethod(){

intk=10;

switch(k){

default:

Thisisthedefaultoutput"

break;

case10:

ten"

case20:

twenty"

A没有正确的选项

B编译成功,运行时出错

C编译和运行成功,输出"

D编译和运行成功,输出"

21 

下面那个方法建议JVM执行垃圾回收操作?

ASystem.free();

BSystem.setGarbageCollection();

CSystem.out.gc();

DSystem.gc();

22 

publicclassAs{

inti=10;

intj;

charz=1;

booleanb;

Asa=newAs();

System.out.println(j);

System.out.println(b);

A编译成功,运行的时候输出0和false

B编译成功,运行的时候输出0和true

C编译不成功,报告变量b和j没有初始化

D编译不成功,变量z必须赋一个char类型的值

23 

publicclassArg{

String[]MyArg;

MyArg=argv;

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

A编译错误

B编译成功,运行出错

C没有正确答案

24 

publicclassStrEq{

StrEqs=newStrEq();

privateStrEq(){

Strings="

Marcus"

Strings2=newString("

if(s==s2){

wehaveamatch"

}else{

Notequal"

A编译错误,构造器不能为private类型

B输出"

C输出"

D编译错误,报告使用“==”错误

25 

importjava.io.*;

publicvoidamethod()throwsFileNotFoundException{}

publicclassExcepDemoextendsBase{

ExcepDemoe=newExcepDemo();

publicvoidamethod(){}

protectedExcepDemo(){

try{

DataInputStreamdin=newDataInputStream(System.in);

Pausing"

din.readByte();

Continuing"

this.amethod();

}catch(IOExceptionioe){}

A编译错误,构造器不能是protected类型

B编译错误,amethod定义中没有抛出Exception

C运行出错,amethod定义中没有抛出Exception

D编译和运行正常。

26 

//Demonstrationofeventhandling

importjava.awt.event.*;

publicclassMyWcextendsFrameimplementsWindowListener{

MyWcmwc=newMyWc();

publicvoidwindowClosing(WindowEventwe){

System.exit(0);

}//EndofwindowClosing

publicvoidMyWc(){

setSize(300,300);

setVisible(true);

}//Endofclass

A编译错误

B编译成功,运行时有输出,可以关闭窗口

C编译成功,运行时无输出

27 

publicclassMyAr{

publicstaticvoidmain(Stringargv[]){

MyArm=newMyAr();

m.amethod();

inti;

A编译成功,输出0

B编译不成功,报告变量i没有初始化

C编译成功,运行没有输出

28 

下面那些选项会编译通过?

Ashortmyshort=99S;

BStringname='

ExcellenttutorialMrGreen'

Ccharc=17c;

Dintz=015;

29 

分析下面的代码,哪个选项可以替代//Here注释,而程序编译和运行没有问题?

publicBase(inti){}

publicclassMyOverextendsBase{

publicstaticvoidmain(Stringarg[]){

MyOverm=newMyOver(10);

MyOver(inti){

super(i);

MyOver(Strings,inti){

this(i);

//Here

AMyOverm=newMyOver();

Bsuper();

Cthis("

Hello"

10);

DBaseb=newBase(10);

30 

下面这行代码会输出什么?

System.out.println(Math.floor(-2.1));

A-2

B2.0

C-3

D-3.0

31 

下面的哪些选项编译和运行没有错误?

charc='

c'

inti=10;

doubled=10;

longl=1;

Strings="

Ac=c+i;

Bs+=i;

Ci+=s;

Dc+=s;

32 

下面哪些选项是Java的关键字?

ANULL

Bnew

CinstanceOf

Dwend

33 

下面哪些表达式是合法的?

ApublicclassMyCalcextendsMath

BMath.max(10,1);

CMath.round(9.99,1);

DMath.mod(4,10);

34 

下面选项中,哪个选项是Runnable接口中定义的方法?

Arun

Bstart

Cyield

Dstop

35 

下面的选项中,哪个选项表述是正确的?

Abyte类型的表示范围为-128to127

Bbyte类型的表示范围为-127to128

Cbyte类型的表示范围为-256to256

Dbyte类型的表示范围为-65536to65535

36 

publicvoidBase(){

System.out.println("

Base"

publicclassInextendsBase{

Ini=newIn();

A编译错误,报告Base是Java的关键字

B编译通过,运行没有输出

C编译通过,并且输出"

D编译错误,报告Base类没有构造方法

37 

Base(inti){

classSevernextendsBase{

Severns=newSevern();

voidSevern(){

Severn"

A编译通过,并且输出"

B编译错误

C编译通过,运行没有输出

D编译通过,并且输出"

38 

下面哪个选项是Java中关键字?

Asizeof

Bmain

Ctransient

DNull

39 

publicclassOmbersley{

booleanb1=true;

if((b1==true)||place(true)){

HelloCrowle"

publicstaticbooleanplace(bpublicstaticbooleanplace(boolean

location){

if(location==true){

Borcetshire"

Powick"

retur

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

当前位置:首页 > 工作范文 > 其它

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

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