




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
选择题 1: Consider the class hierarchy shown below: - class FourWheeler implements DrivingUtilities class Car extends FourWheeler class Truck extends FourWheeler class Bus extends FourWheeler class Crane extends FourWheeler - Consider the following code below: 1.DrivingUtilities du; 2.FourWheeler fw; 3.Truck myTruck = new Truck(); 4.du = (DrivingUtilities)myTruck; 5.fw = new Crane(); 6.fw = du; Which of the statements below are true? Choices: A.Line 4 will not compile because an interface cannot refer to an object. B.The code will compile and run. C.The code will not compile without an explicit cast at line 6, because going down the hierarchy without casting is not allowed. D.The code will compile if we put an explicit cast at line 6 but will throw an exception at runtime. 2:A class design requires that a member variable should be accessible only by same package, which modifer word should be used? A.protected B.public C.no modifer D.private 3: Whatistheresultwhenyoucompileandrunthefollowingcode? publicclassThrowsDemo staticvoidthrowMethod() System.out.println(InsidethrowMethod.); thrownewIllegalAccessException(demo); publicstaticvoidmain(Stringargs) try throwMethod(); catch(IllegalAccessExceptione) System.out.println(Caught+e); Choices:What is the result when you compile and run the following code? public class ThrowsDemo static void throwMethod() System.out.println(Inside throwMethod.); throw new IllegalAccessException(demo); public static void main(String args) try throwMethod(); catch (IllegalAccessException e) System.out.println(Caught + e); Choices:A.Compilation error B.Runtime error C.Compile successfully, nothing is printed. D.Inside throwMethod. followed by caught:java.lang.IllegalAccessExcption: demo 4: Inthefollowingcode,whichistheearlieststatement,wheretheobjectoriginallyheldine,maybegarbagecollected: 1.publicclassTest 2.publicstaticvoidmain(Stringargs) 3.Employeee=newEmployee(Bob,48); 4.e.calculatePay(); 5.System.out.println(e.printDetails(); 6.e=null; 7.e=newEmployee(Denise,36); 8.e.calculatePay(); 9.System.out.println(e.printDetails(); 10. 11. OnlyOne:In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected: 1.public class Test 2. public static void main (String args ) 3. Employee e = new Employee(Bob, 48); 4. e.calculatePay(); 5. System.out.println(e.printDetails(); 6. e = null; 7. e = new Employee(Denise, 36); 8. e.calculatePay(); 9. System.out.println(e.printDetails(); 10. 11.Only One: A.Line 10 B.Line 11 C.Line 7 D.Line 8 5: Whatwillbetheresultofexecutingthefollowingcode? publicstaticvoidmain(Stringargs) chardigit=a; for(inti=0;i10;i+) switch(digit) casex: intj=0; System.out.println(j); default: intj=100; System.out.println(j); inti=j; System.out.println(i); Choices:What will be the result of executing the following code? public static void main(String args) char digit = a; for (int i = 0; i 10; i+) switch (digit) case x : int j = 0; System.out.println(j); default : int j = 100;System.out.println(j); int i = j; System.out.println(i); Choices:A.100 will be printed 11 times. B.The code will not compile because the variable i cannot be declared twice within the main() method. C.The code will not compile because the variable j cannot be declared twice within the switch statement. D.None of these. 6: Whatresultsfromattemptingtocompileandrunthefollowingcode? publicclassTernary publicstaticvoidmain(Stringargs) inta=5; System.out.println(Valueis-+(a5)?9.9:9); Choices:What results from attempting to compile and run the following code? public class Ternarypublic static void main(String args)int a = 5;System.out.println(Value is - + (a 4) System.out.println(“Test1”); elseif(x9) System.out.println(“Test2”); else System.out.println(“Test3”); Whichrangeofvaluexwouldproduceofoutput“Test2”?Give the code fragment:if(x4)System.out.println(“Test 1”);else if (x9)System.out.println(“Test 2”);else System.out.println(“Test 3”);Which range of value x would produce of output “Test 2”? A.x4 C.x9 D.None 13: Whatwillbetheresultofexecutingthefollowingcode? /Filename;SuperclassX.java packagepackageX; publicclassSuperclassX protectedvoidsuperclassMethodX() intsuperclassVarX; /FilenameSubclassY.java 1.packagepackageX.packageY; 2. 3.publicclassSubclassYextendsSuperclassX 4. 5.SuperclassXobjX=newSubclassY(); 6.SubclassYobjY=newSubclassY(); 7.voidsubclassMethodY() 8. 9.objY.superclassMethodX(); 10.inti; 11.i=objY.superclassVarX; 12. 13. Choices:What will be the result of executing the following code? / Filename; SuperclassX.javapackage packageX; public class SuperclassXprotected void superclassMethodX()int superclassVarX; / Filename SubclassY.java1.package packageX.packageY;2.3.public class SubclassY extends SuperclassX4.5.SuperclassX objX = new SubclassY();6.SubclassY objY = new SubclassY();7.void subclassMethodY()8.9.objY.superclassMethodX();10.int i;11.i = objY.superclassVarX;12.13. Choices:A.Compilation error at line 5 B.Compilation error at line 9 C.Runtime exception at line 11 D.None of these 14:假定a和b为int型变量,则执行下述语句组后,b的值为 a=1; b=10; do b-=a; a+; while (b-0); A.9 B.-2 C.-1 D.8 15:Which statement about the garbage collection mechanism are true? A.Garbage collection require additional programe code in cases where multiple threads are running. B.The programmer can indicate that a reference through a local variable is no longer of interest. C.The programmer has a mechanism that explicity and immediately frees the memory used by Java objects. D.The garbage collection mechanism can free the memory used by Java Object at explection time. 简答题 16:tomcat中,什么是DefaultServlet?他的功能是
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 人教版七年级上册第二单元 第一课大洲和大洋说课稿2
- 第一课 灯笼教学设计-2025-2026学年小学劳动四年级上册粤教版(主编:徐长发)
- 2025年中国高纯碳酸氢钠行业市场分析及投资价值评估前景预测报告
- 4.3 工业-分布与发展 教学设计-八年级地理上学期人教版
- 医疗校准专业知识培训课件
- 第1节 生物的进化说课稿高中生命科学沪科版第三册-沪科版
- 体育与健康九年级人教版《羽毛球正手发高远球》教学设计
- 第4节 植物在自然界中的作用新教材七年级下册生物同步教学设计(人教版2024)
- 2025年中国呋喃树脂胶泥行业市场分析及投资价值评估前景预测报告
- 口腔供应室知识培训总结课件
- 【国际音标】初高中英语音标拼读规则表(附口型图)
- 动火作业施工方案5篇
- 浙教版九年级科学上册讲练测专题提升Ⅳ动态电路中电功电功率变化问题(原卷版+解析)
- JTS-252-2015水运工程施工监理规范
- DB4405-T 303-2023 狮头鹅屠宰操作规程
- 坚持人民至上 工会研讨发言
- 杭州师范大学2013年841无机化学考研真题
- 美学原理全套教学课件
- 子宫脱垂试题及答案
- 中国政治思想史复习资料
- 高中音乐鉴赏 第一单元 学会聆听 第一节《音乐要素及音乐语言》
评论
0/150
提交评论