JAVA认证试题解析.docx

上传人:b****5 文档编号:14614751 上传时间:2023-06-25 格式:DOCX 页数:104 大小:51KB
下载 相关 举报
JAVA认证试题解析.docx_第1页
第1页 / 共104页
JAVA认证试题解析.docx_第2页
第2页 / 共104页
JAVA认证试题解析.docx_第3页
第3页 / 共104页
JAVA认证试题解析.docx_第4页
第4页 / 共104页
JAVA认证试题解析.docx_第5页
第5页 / 共104页
JAVA认证试题解析.docx_第6页
第6页 / 共104页
JAVA认证试题解析.docx_第7页
第7页 / 共104页
JAVA认证试题解析.docx_第8页
第8页 / 共104页
JAVA认证试题解析.docx_第9页
第9页 / 共104页
JAVA认证试题解析.docx_第10页
第10页 / 共104页
JAVA认证试题解析.docx_第11页
第11页 / 共104页
JAVA认证试题解析.docx_第12页
第12页 / 共104页
JAVA认证试题解析.docx_第13页
第13页 / 共104页
JAVA认证试题解析.docx_第14页
第14页 / 共104页
JAVA认证试题解析.docx_第15页
第15页 / 共104页
JAVA认证试题解析.docx_第16页
第16页 / 共104页
JAVA认证试题解析.docx_第17页
第17页 / 共104页
JAVA认证试题解析.docx_第18页
第18页 / 共104页
JAVA认证试题解析.docx_第19页
第19页 / 共104页
JAVA认证试题解析.docx_第20页
第20页 / 共104页
亲,该文档总共104页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

JAVA认证试题解析.docx

《JAVA认证试题解析.docx》由会员分享,可在线阅读,更多相关《JAVA认证试题解析.docx(104页珍藏版)》请在冰点文库上搜索。

JAVA认证试题解析.docx

JAVA认证试题解析

1.

Given:

1.publicclassreturnIt{

2.returnTypemethodA(bytex,doubley){

3.return(short)x/y*2;

4.}

5.}

WhatisthevalidreturnTypeformethodAinline2?

A.int

B.byte

C.long

D.short

E.float

F.double

 

AnswerF

注释:

short类型的x,除以double类型的y,再乘int的2,所以结果是double类型的。

注意第三行的强制转换,只是转换了x。

2.

1)classSuper{

2)publicfloatgetNum(){return3.0f;}

3)}

4)

5)publicclassSubextendsSuper{

6)

7)}

whichmethod,placedatline6,willcauseacompilererror?

A.publicfloatgetNum(){return4.0f;}

B.publicvoidgetNum(){}

C.publicvoidgetNum(doubled){}

D.publicdoublegetNum(floatd){return4.0d;}

Answer:

B

注意这道题主要考的是方法的overload和override。

对于overload,只有参数列表不同,才做为标准,而返回值和访问控制关键字不能做为标准,所以B错在方法名相同,但只有返回值不同,这是错的。

C和D是正确的overload。

对于override,则访问控制关键字只能更加公有化,异常只能是超类方法抛出的异常的子类,也可以不抛出。

返回类型,参数列表必须精确匹配。

所以A是正确的override。

3.

1)publicclassFoo{

2)publicstaticvoidmain(Stringargs[]){

3)try{return;}

4)finally{System.out.println("Finally");}

5)}

6)}

whatistheresult?

A.Theprogramrunsandprintsnothing.

B.Theprogramrunsandprints“Finally”.

C.Thecodecompiles,butanexceptionisthrownatruntime.

D.Thecodewillnotcompilebecausethecatchblockismissing.

Answer:

b

try......catch......finally的问题。

程序中如果遇到return,则finally块先被执行,然后再执行retrun,而finally块后面的语句将不被执行。

如果遇到System.exit

(1),则finally块及其后的语句都不执行,整个程序退出,还执行什么呀。

4.

1)publicclassTest{

2)publicstaticStringoutput="";

3)publicstaticvoidfoo(inti){

4)try{

5)if(i==1){

6)thrownewException();

7)}

8)output+="1";

9)}

10)catch(Exceptione){

11)output+="2";

12)return;

13)}

14)finally{

15)output+="3";

16)}

17)output+="4";

18)}

19)publicstaticvoidmain(Stringargs[]){

20)foo(0);

21)foo

(1);

22)

23)}

24)}

whatisthevalueofoutputatline22?

 

Asnwer:

13423

执行第一个foo(0)时,执行第8条语句,output=1,然后执行语句15,output=13,然后是17条,output=134,因为是static类型的变量,所以任何对其值的修改都有效。

执行第二条foo

(1),先执行语句5,结果抛出异常,转到catch块,output=1342,finally任何情况下都执行,所以output=13423,然后return跳出方法体,所以output=13423

5.

1)publicclassIfElse{

2)publicstaticvoidmain(Stringargs[]){

3)if(odd(5))

4)System.out.println("odd");

5)else

6)System.out.println("even");

7)}

8)publicstaticintodd(intx){returnx%2;}

9)}

whatisoutput?

Answer:

编译错误。

if中的判断条件的结果必须是boolean类型的。

注意这里说的是结果.

6.

1)classExceptionTest{

2)publicstaticvoidmain(Stringargs[]){

3)try{

4)methodA();

5)}catch(IOExceptione){

6)System.out.println("caughtIOException");

7)}catch(Exceptione){

8)System.out.println("caughtException");

9)}

10)}

11)}

IfmethodA()throwsaIOException,whatistheresult?

Answer:

caughtIOException

如果methodA()抛出IOExecption,被语句6捕获,输出caughtIOException,然后呢?

然后就结束了呗。

7.

1)inti=1,j=10;

2)do{

3)if(i++>--j)continue;

4)}while(i<5);

AfterExecution,whatarethevalueforiandj?

A.i=6j=5

B.i=5j=5

C.i=6j=4

D.i=5j=6

E.i=6j=6

Answer:

d

程序一直循环,直到i=4,j=6时,执行完语句3后,i会++,这时i就等于了5,continue后就不能再循环了,所以选D。

8.

1)publicclassX{

2)publicObjectm(){

3)Objecto=newFloat(3.14F);

4)Object[]oa=newObject[1];

5)oa[0]=o;

6)o=null;

7)oa[0]=null;

8)System.out.println(oa[0]);

9)}

10)}

whichlineistheearliestpointtheobjectareferedisdefinitelyelibiletobegarbagecollectioned?

A.Afterline4

B.Afterline5

C.Afterline6

D.Afterline7

E.Afterline9(thatis,asthemethodreturns)

Answer:

d

当执行第6行后,仍然有对象指向o,所以o不能满足条件,当第7条语句被执行后,就再也没有对象指向o了,所以选D。

9.

1)interfaceFoo{

2)intk=0;

3)}

4)publicclassTestimplementsFoo{

5)publicstaticvoidmain(Stringargs[]){

6)inti;

7)Testtest=newTest();

8)i=test.k;

9)i=Test.k;

10)i=Foo.k;

11)}

12)}

Whatistheresult?

A.Compilationsucceeds.

B.Anerroratline2causescompilationtofail.

C.Anerroratline9causescompilationtofail.

D.Anerroratline10causescompilationtofail.

E.Anerroratline11causescompilationtofail.

Answer:

A

编译通过,通过测试的

10.

whatisreservedwordsinjava?

A.run

B.default

C.implement

D.import

 

Answer:

b,D

11.

1)publicclassTest{

2)publicstaticvoidmain(String[]args){

3)Stringfoo=args[1];

4)Sringbar=args[2];

5)Stringbaz=args[3];

6)}

7)}

javaTestRedGreenBlue

whatisthevalueofbaz?

A.bazhasvalueof""

B.bazhasvalueofnull

C.bazhasvalueof"Red"

D.bazhasvalueof"Blue"

E.bazhasvalueof"Green"

F.thecodedoesnotcompile

G.theprogramthrowanexception

 

Answer:

G

当执行javaTestRedGreenBlue时,数组args只有[0][1][2],运行时ArrayIndexOutOfBoundsException这个异常会被抛出,数组越界。

12.

intindex=1;

intfoo[]=newint[3];

intbar=foo[index];

intbaz=bar+index;

whatistheresult?

A.bazhasavalueof0

B.bazhasvalueof1

C.bazhasvalueof2

D.anexceptionisthrown

E.thecodewillnotcompile

Answer:

b

数组初始化后默认值是0,所以baz=0+1=1

13.

whichthreearevaliddeclaractionofafloat?

A.floatfoo=-1;

B.floatfoo=1.0;

C.floatfoo=42e1;

D.floatfoo=2.02f;

E.floatfoo=3.03d;

F.floatfoo=0x0123;

Answer:

A,D,F

其它的系统都会认为是double类型,所以出错。

说一下A和C的区别吧,-1系统会认为是一个int类型,把int类型再赋给float类型的foo,当然没错了,可C就不同啦,42e1是int类型吗?

14.

1)publicclassFoo{

2)publicstaticvoidmain(Stringargs[]){

3)Strings;

4)System.out.println("s="+s);

5)}

6)}

whatistheresult?

A.Thecodecompilesand“s=”isprinted.

B.Thecodecompilesand“s=null”isprinted.

C.Thecodedoesnotcompilebecausestringsisnotinitialized.

D.Thecodedoesnotcompilebecausestringscannotbereferenced.

E.Thecodecompiles,butaNullPointerExceptionisthrownwhentoStringiscalled.

Answer:

C

只有实例变量系统才给予自动赋默认值的这种待遇

15.

1)publicclassTest{

2)publicstaticvoidmain(Stringargs[]){

3)inti=oxFFFFFFF1;

4)intj=~i;

5)

6)}

7)}

whichisdecimalvalueofjatline5?

A.0

B.1

C.14

D.-15

E.compileerroratline3

F.compileerroratline4

Answer:

C

算一算就知道了。

16.

floatf=4.2F;

Floatg=newFloat(4.2F);

Doubled=newDouble(4.2);

Whicharetrue?

A.f==g

B.g==g

C.d==f

D.d.equals(f)

Ed.equals(g)

F.g.equals(4.2);

Answer:

B

==两边类型不同不相等。

所以A和C不等。

equals只能用于引用类型,不能用于基本类型,所以D不对,而且两边类型不兼容的话,即使对象的内容一样,也不相等,所以E和F不对。

17.

1)publicclassTest{

2)publicstaticvoidadd3(Integeri){

3)intval=i.intValue();

4)val+=3;

5)i=newInteger(val);

6)}

7)publicstaticvoidmain(Stringargs[]){

8)Integeri=newInteger(0);

9)add3(i);

10)System.out.println(i.intValue());

11)}

12)}

whatistheresult?

A.compilefail

B.printout"0"

C.printout"3"

D.compilesuccededbutexceptionatline3

Answer:

b

在第五行里,程序又操作了New,重新分配了内存空间。

所以此i非彼i啦。

18.

1)publicclassTest{

2)publicstaticvoidmain(String[]args){

3)System.out.println(6^3);

4)}

5)}

whatisoutput?

Answer:

5算呗。

19.

1)publicclassTest{

2)publicstaticvoidstringReplace(Stringtext){

3)text=text.replace('j','l');

4)}

5)publicstaticvoidbufferReplace(StringBuffertext){

6)text=text.append("c");

7)}

8)publicstaticvoidmain(Stringargs[]){

9)StringtextString=newString("java");

10)StringBuffertextBuffer=newStringBuffer("java");

11)StringReplace(textString);

12)bufferReplace(textBuffer);

13)System.out.println(textString+textBuffer);

14)}

15)}

whatistheoutput?

Answer:

javajavac

textString是String类型的,具有不变性,语句3其实是创建了一个新的字符串,而不是修改原来的textString,而对于StringBuffer类型的对象,则所有修改都是实在的。

所以在语句6中textBuffer变成了javac,所以输出为javajavac。

20.

1)publicclassConstOver{

2)publicConstOver(intx,inty,intz){}

3)}

whichtwooverloadtheConstOverconstructor?

A.ConstOver(){}

B.protectedintConstOver(){}

C.privateConstOver(intz,inty,bytex){}

D.publicvoidConstOver(bytex,bytey,bytez){}

E.publicObjectConstOver(intx,inty,intz){}

Answer:

a,c

主要的问题是overload,参数列表必须不同,方法名相同,访问控制无限制。

也无异常限制。

这道题因为是构造器,所以B,D和E不对,因为构造器不能有返回类型。

21.

1)publicclassMethodOver{

2)publicvoidsetVar(inta,intb,floatc){}

3)}

whichoverloadthesetVar?

A.privatevoidsetVar(inta,floatc,intb){}

B.protectedvoidsetVar(inta,intb,floatc){}

C.publicintsetVar(inta,floatc,intb){returna;}

D.publicintsetVar(inta,floatc){returna;}

Answer:

a,c,d

overload无访问控制限制,所以A对,顺序也属于参数列表,顺序不同也一样是overload,所以C正确,D当然正确了,参数列表明显不同。

22.

1)classEnclosingOne{

2)publicclassInsideOne{}

3)}

4)publicclassInnerTest{

5)publicstaticvoidmain(Stringargs[]){

6)EnclosingOneeo=newEnclosingOne();

7)//insertcodehere

8)}

9)}

A.InsideOneei=eo.newInsideOne();

B.eo.InsideOneei=eo.newInsideOne();

C.InsideOneei=EnclosingOne.newInsideOne();

D.InsideOneei=eo.newInsideOne();

E.EnclosingOne.InsideOneei=eo.newInsideOne();

Answer:

e

这里边的一些形式是固定的。

(1)静态方法访问非静态内类:

方法为:

Outermyouter=newOuter();//这里的myouter是创建的外部类的对象。

Outer.Innermyinner=myouter.newInner();//myinner是内类的对象。

然后再myinner.showName();//showName()是外类中的非静态方法。

(2)非静态方法访问非静态内类

直接创建该内部类的对象:

newInner().showName();

(3)静态方法访问静态内类:

也是直接创建该内部类的对象,即Innermyinner=newInner(),或者Outer.Innermyinner=newOuter.Inner()也行得通哦。

23.

Whatis"isa"relation?

A.publicinterfaceColor{}

publicclassShape{privateColorcolor;}

B.interfaceComponent{}

classContainerimplementsComponent{

privateComponent[]children;

}

C.publicclassSpecies{}

publicclassAnimal{privateSpeciesspecies;}

Answer:

b

"isa"意思为是什么:

定义了一个超类和一个子类之间的一种直接关系:

子类是超类的一种。

也即是继承的关系

24.

1)packagefoo;

2)

3)publicclassOuter{

4)publicstaticclassInner{

5)}

6)}

whichistruetoinstantiatedInnerclassinsideOuter?

A.newOuter.Inner()

B.newInner()

Answer:

a,b

25.

classBaseClass{

privatefloatx=1.0f;

privatefloatgetVar(){r

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

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2