Sunjava认证考试答案_第1页
Sunjava认证考试答案_第2页
Sunjava认证考试答案_第3页
Sunjava认证考试答案_第4页
Sunjava认证考试答案_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Sunjava认证考试答案

1.Whatgetsprintedwhenthefollowingprogram

iscompiledandrun?

classTest{

publicstaticvoidmain(Stringargs[]){

inti;

do{

i++;

}while(i0);

System.out.println(i);

}

}

Select1correctanswer:

A.Theprogramdoesnotcompileasiisnotinitialized.

B.Theprogramcompilesbutdoesnotrun.

C.Theprogramcompilesandrunsbutdoesnotprintanything.

D.Theprogramprints0.

E.Theprogramprints1.

答案:A:假如没有初始化便使用根本变量类型,会导致编译时特别,程序不能编译。

2.Whatgetsprintedwhenthefollowingprogram

iscompiledandrun?

publicclassXYZ{

publicstaticvoidmain(Stringargs[]){

inti,j,k;

for(i=0;i3;i++)

{

for(j=1;j4;j++)

{

for(k=2;k5;k++)

{

if((i==j)(j==k))

System.out.println(i);

}}}}}

Select1correctanswer:

A.0

B.1

C.2

D.3

E.4

答案:C

3.Giventhefollowingcode:

classBase{}

publicclassMyCastextendsBase{

staticbooleanb1=false;

staticinti=-1;

staticdoubled=10.1;

publicstaticvoidmain(Stringargv[]){

MyCastm=newMyCast();

Baseb=newBase();

//Here

}

}

Whichofthefollowing,ifinsertedatthecomment//Here

willallowthecodetocompileandrunwithouterror?

Select2correctanswers:

A.b=m;

B.m=b;

C.d=i;

D.b1=i;

解析:A从子类型到父类型的转换是扩展引用转换,不需要在运行时实行特别的动作,不会在运行时抛出特别。

B从超类型到子类型的”转换是收缩引用转换,需要在运行时执行测试,以查明实际的引用值是否是新类型的合法值.假如不是,则会抛出ClassCascException。在这里,b本身不是MyCast类型的值,因此会导致运行时特别。

C从int到double的转换是扩展根本转换,根本类型之间的扩展转换永久不会导致运行时特别。但从int或long到float,或者是从long到double都可能导致精度丧失。

D不允许进展int和boolean之间的类型转换

答案:A、C

4.Giventhefollowingclasseswhichofthefollowing

willcompilewithouterror?

interfaceIFace{}

classCFaceimplementsIFace{}

classBase{}

publicclassObRefextendsBase{

publicstaticvoidmain(Stringargv[])

{

ObRefob=newObRef();

Baseb=newBase();

Objecto1=newObject();

IFaceo2=newCFace();

}

}

Select3correctanswers:

A.o1=o2;

B.b=ob;

C.ob=b;

D.o1=b;

解析:A任何对象都可以赋给Object类型的对象,正确

B子类赋给超类是扩展引用转换,可以进展

C收缩引用转换,错误

D扩展引用转换,可以进展

答案ABD

5.Whatistheresultofcompilingandrunningthefollowingcode?

1publicclassTest{

2staticinttotal=10;

3publicstaticvoidmain(Stringargs[]){

4newTest();

5}

6publicTest(){

7System.out.println(Intest);

8System.out.println(this);

9inttemp=this.total;

10if(temp5){

11System.out.println(temp);

12}

13}

14}

Select1correctanswer:

A.Theclasswillnotcompile

B.Thecompilerreportsanerroratline2

C.Thecompilerreportsanerroratline9

D.Thevalue10isoneoftheprintedelements

E.Theclasscompilesbutgeneratesaruntimeerror

答案:D由于test类没有overridetoString方法,故在调用println(this)时会直接显示类的有关信息。

6.Carefullyexaminethefollowingcode:

publicclassStaticTest{

static{System.out.println(Hithere);}

publicvoidprint(){

System.out.println(Hello);

}

publicstaticvoidmain(Stringargs[]){

StaticTestst1=newStaticTest();

st1.print();

StaticTestst2=newStaticTest();

st2.print();

}}

WhenwillthestringHitherebeprinted?

Select1correctanswer:

A.Never

B.Eachtimeanewinstanceiscreated

C.Once,whentheclassisfirstloadedintotheJVM

D.Onlywhenthestaticmethodiscalledexplicitly

答案C

Java虚拟机标准商定,类的初始化发生在首次主动使用时。静态变量和静态初始化块的先后,实际上取决于它们在类中消失的先后挨次。

7.Giventhefollowingcodewhatistheeffectofabeing5?

publicclassTest{

publicvoidadd(inta){

loop:for(inti=1;i3;i++){

for(intj=1;j3;j++){

if(a==5){

breakloop;

}

System.out.println(i*j);

}

}

}

}

Select1correctanswer:

A.Generatesaruntimeerror

B.Throw

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论