




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
选择题 1: Strings=”ExampleString”;Whichoperationisnotlegal?String s=”Example String”;Which operation is not legal?A.int i=s.length(); B.s3=”x”; C.String short_s=s.trim(); D.String t=”root”+s; 2:What is written to the standard output given the following statement:System.out.println(4|7); Select the right answer: A.4 B.5 C.6 D.7 3: Whathappenswhenyoutrytocompileandrunthefollowingprogram? classMystery Strings; publicstaticvoidmain(Stringargs) Mysterym=newMystery(); m.go(); voidMystery() s=”constructor”; voidgo() System.out.println(s); What happens when you try to compile and run the following program?class MysteryString s;public static void main(String args)Mystery m=new Mystery();m.go();void Mystery()s=”constructor”;void go()System.out.println(s);A.this code compliles but throws an exception at runtime B.this code runs but nothing appears in the standard output C.this code runs and “constructor” in the standard output D.this code runs and writes ”null” in the standard output 4:A class design requires that a particular member variable must be accessible for direct access by any subclasses of this class. but otherwise not by classes which are not members of the same package. What should be done to achieve this? A.The variable should be marked public B.The variable should be marked private C.The variable should be marked protected D.The variable should have no special access modifier 5: Whatwillhappenwhenyouattempttocompileandrunthefollowingcode? intOutput=10; booleanb1=false; if(b1=true)&(Output+=10)=20) System.out.println(Weareequal+Output); else System.out.println(Notequal!+Output); Choices:What will happen when you attempt to compile and run the following code? int Output = 10;boolean b1 = false; if(b1 = true) & (Output += 10) = 20) System.out.println(We are equal + Output); else System.out.println(Not equal! + Output); Choices:A.Compilation error, attempting to perform binary comparison on logical data type B.Compilation and output of We are equal 10. C.Compilation and output of Not equal! 20. D.Compilation and output of Not equal! 10. 6: 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 7: 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 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 10: Whatwillhappenwhenyouattempttocompileandrunthefollowingcode? (Assumethatthecodeiscompiledandrunwithassertionsenabled.) publicclassAssertTest publicvoidmethodA(inti) asserti=0:methodB(); System.out.println(i); publicvoidmethodB() System.out.println(Thevaluemustnotbenegative); publicstaticvoidmain(Stringargs) AssertTesttest=newAssertTest(); test.methodA(-10); What will happen when you attempt to compile and run the following code?(Assume that the code is compiled and run with assertions enabled.)public class AssertTestpublic void methodA(int i)assert i = 0 : methodB();System.out.println(i);public void methodB() System.out.println(The value must not be negative);public static void main(String args)AssertTest test = new AssertTest();test.methodA(-10); A.it will print -10 B.it will result in AssertionError showing the message-“the value must not be negative”. C.the code will not compile. D.None of these. 11: ThefollowingcodeisentirecontentsofafilecalledExample.java,causespreciselyoneerrorduringcompilation: classSubClassextendsBaseClass classBaseClass() Stringstr; publicBaseClass() System.out.println(“ok”); publicBaseClass(Strings) str=s; publicclassExample publicvoidmethod() SubClasss=newSubClass(“hello”); BaseClassb=newBaseClass(“world”); Whichlinewouldbecausetheerror?The following code is entire contents of a file called Example.java,causes precisely one error during compilation: class SubClass extends BaseClass class BaseClass() String str; public BaseClass() System.out.println(“ok”); public BaseClass(String s) str=s; public class Example public void method() SubClass s=new SubClass(“hello”); BaseClass b=new BaseClass(“world”); Which line would be cause the error? A.9 B.10 C.11 D.12 12: 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 5) ? 9.9 : 9); Choices:A.prints: Value is - 9 B.Compilation error C. prints: Value is - 5 D.None of these 13:Which declares for native method in a java class corrected? A.public native void method() B.public native void method(); C.public native method(); D.public void native method(); 14:Which code fragments would correctly identify the number of arguments passed via command line to a Java application, exclude the name of the class that is being invoke. A.int count = args.length; B.int count = args.length-1; C.int count=0; while(argscount!=null) count+; D.int count=0;while (!(argscount.equals(“”) count+; 15:Which statements about Java code security are not true? A.The bytecode verifier loads all classes needed for the execution of a program. B.Executing code is performed by the runtime interpreter. C.At runtime the bytecodes are loaded, checked and run in an interpreter. D.The class loader adds security by separating the namespaces for the classes of the local file system from those imported from network sources. 16:关于垃圾收集的哪些叙述是对的。 A.程序开发者必须自己创建一个线程进行内存释放的工作。 B.垃圾收集将检查并释放不再使用的内存。 C.垃圾收集允许程序开发者明确指定并立即释放该内存。 D.垃圾收集能够在期望的时间释放被java对象使用的内存。 17: 1.publicclassX 2.publicobjectm() 3.objecto=newfloat(3.14F); 4.objectoa=newobject1; 5.oa0=o; 6.o=null; 7.oa0=null; 8.returno; 9
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 消防安全检查员培训课件
- 医疗器械经理工作汇报
- 东北师范大学民俗馆讲解
- 新旧技术合作协议更替原协议作废确认书
- 节假日租车合同终止及车辆返还标准范本
- 私立幼儿园教师儿童社会实践活动指导聘用合同
- 离婚协议书中双方共同财产分割方案示范
- 离异父母子女抚养费增加及支付条件变更协议
- 离婚子女抚养费支付及探望权调整补充协议
- 夫妻关系修复后再破裂协议书范本
- 2025年自来水集团招聘笔试参考题库含答案解析
- 新教师入职工作安排流程
- 2024年中国室内高尔夫设备市场调查研究报告
- 《商务英语视听说(3)》教学大纲
- 洱海保护课件
- (北师大版2024)七年级数学上学期期中测试卷
- 2024八年级数学上册第12章一次函数12.1函数第1课时上课课件新版沪科版
- 义务教育法主题班会课件
- 2024年秋新译林版英语三年级上册 Unit 3第1课时 Cartoon time 教学课件
- 全国计算机等级考试一级历年考试真题试题库(含答案)
- 研学旅行合同
评论
0/150
提交评论