版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 绿色清新风劳动节安全教育主题
- 注册会计师税法中反避税管理的实施程序
- 5.5 运行与维护数据库
- 以生为本激扬成长-新时代高中班级管理的实践与创新
- 纺织厂生产设备使用细则
- 麻纺产品追溯细则
- 苏科版(新教材)小学信息科技五年级下册每课教学反思
- 2026年宿州九中教育集团(宿马南校区) 教师招聘备考题库带答案详解(突破训练)
- 2026山东济南市中心医院招聘博士研究生(控制总量)70人备考题库及参考答案详解
- 2026上半年四川成都职业技术学院(考核)招聘高层次人才8人备考题库附参考答案详解(b卷)
- 山西省吕梁市2025-2026学年高三第二次模拟调研测试生物+答案
- 2026山东青岛海上综合试验场有限公司招聘38人备考题库含完整答案详解(全优)
- 大型赛事活动安保服务方案投标文件(技术标)
- 2026年上半年中小学教师资格考试教育知识与能力(中学)真题附答案解析
- 施工工地员工考核管理制度(3篇)
- 医院耗材监督考核制度
- 2025特变电工校园招聘200人笔试历年常考点试题专练附带答案详解2套试卷
- 2026年山东潍坊市高三一模高考生物模拟试卷(含答案详解)
- 中国商飞在线测评题
- 农业经济学ppt全套教学课件
- 低压电工基础知识资料
评论
0/150
提交评论