已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
J2SE 知识点巩固提高题选择题解答方式: 1. 写出答案 2. 写出做出选择的理由 3. 简略书写相关知识点要点Question 1Click the Exhibit button.1. public class A 2.3. static int counter = 0;4.5. public static int getInstanceCount() 6. return counter;7. 8.9. public A() 10. +counter;11. 12.13. Given this code from Class B:25.A a1 =new A();26. A a2 =new A();27. A a3 =new A();28. System.out.printIn(A.getInstanceCount() );What is the result?A. Compilation of class A fails.B. Line 28 prints the value 3 to System.out.C. Line 28 prints the value 1 to System.out.D. A runtime error occurs when line 25 executes.E. Compilation fails because of an error on line 28.Question 241. Given:10. class One 11. public One foo() return this; 12. 13. class Two extends One 14. public One foo() return this; 15. 16. class Three extends Two 17. / insert method here18. Which two methods, inserted individually, correctly complete theThree class? (Choose two.)A. public void foo() B. public int foo() return 3; C. public Two foo() return this; D. public Three foo() return this; E. public Object foo() return this; 重写方法返回值不能比父类广。Question 3What will happen when you try compiling and running this code?public class Teststatic int i=10;public static void main(String argv)Test t = new Test();t.myMethod(t);public void myMethod(Test t)int i = 99;function(t);System.out.println(t.i);public void function(Test t)t.i = t.i * 2;static i+;A. 编译错误, 静态方法不能调用实例方法.B. An output of 99C. An output of 198D. An output of 22E. An error at runtimeQuestion 4Given:1. public class Plant 2. private String name;3. public Plant(String name) = name; 4. public String getName() return name; 5. 1. public class Tree extends Plant 2. public void growFruit() 3. public void dropLeaves() 4. Which is true? (choose two)A. The code will compile without changes.B. The code will compile if public Tree() super(“fern”); is added to theTree class.C. The code will compile if public Plant() Tree(); is added to thePlant class.D. The code will compile if public Plant() this(”fern”); is added tothe Plant class.E. The code will compile if public Plant() super(”fern”); is added tothe Plant class.Question 5Given:11. public class Test 12. public static void main(String args) 13. int x =5;14. boolean b1 = true;15. boolean b2 = false;16.17.if(x=4) & !b2)18. System.out.print(”l “);19. System.out.print(”2 “);20. if (b2 = true) & b1)21. System.out.print(”3 “);22. 23. What is the result?A. 2B. 3C. 1 2D. 2 3E. 1 2 3F. Compilation fails.G. Au exceptional is thrown at runtime.Question 6Given:10. interface Foo 11. class Alpha implements Foo 12. class Beta extends Alpha 13. class Delta extends Beta 14. public static void main( String args) 15. Beta x = new Beta();16. / insert code here17. 18. Which code, inserted at line 16, will cause ajava.lang.ClassCastException?A. Alpha a = x;B. Foo f= (Delta)x;C. Foo f= (Alpha)x;D. Beta b = (Beta)(Alpha)x;Question 7Assume that country is set for each class.Given:10. public class Money 11. private String country, name;12. public String getCountry() return country; 13.and:24. class Yen extends Money 25. public String getCountry() return super.country; 26. 27.28. class Euro extends Money 29. public String getCountry(String timeZone) 30. return super.getCountry();31. 32. Which two are correct? (Choose two.)A. Yen returns correct values.B. Euro returns correct values.C. An exception is thrown at runtime.D. Yen and Euro both return correct values.E. Compilation fails because of an error at line 25.F. Compilation fails because of an error at line 30.Question 812. Given:13. public class Pass 14. public static void main(String args) 15. int x=5;16. Pass p = new Pass();17. p.doStuff(x);18. System.out.print(” main x = “+ x);19. 20.21. void doStuff(int x) 22. System.out.print(” doStuff x = “+ x+);23. 24. What is the result?A. Compilation fails.B. An exception is thrown at runtime.C. doStuffx = 6 main x = 6D. doStuffx = 5 main x = 5E. doStuffx = 5 main x = 6F. doStuffx = 6 main x = 5 Question 9Given:1. class TestA 2. public void start() System.out.println(”TestA”); 3. 4. public class TestB extends TestA 5. public void start() System.out.println(”TestB”); 6. public static void main(String args) 7. (TestA)new TestB().start();8. 9. What is the result?A. TestAB. TestBC. Compilation fails.D. An exception is thrown at runtime.Question 10What will happen when you attempt to compile and run this code?abstract class Baseabstract public void myfunc() ;public void another()System.out.println(Another method);public class Abs extends Basepublic static void main(String argv)Base b= new Abs(); /Ab. myfunc(); /Bpublic void myfunc()System.out.println(My Func);public void amethod()myfunc();1 choice1) The code will compile and run, printing out the words My Func2) The compiler will complain error at /A.3) The compiler will complain error at /B.4) The compiler will complain error at other position.Question 11What will be the output when the following code is compiled and run (Assuming written inside main)?String s1 = new String(amit);System.out.println(s1.replace(m,r);System.out.println(s1);String s3 = arit;String s4 = arit;String s2 = s1.replace(m,r);System.out.println(s2 = s3);System.out.println(s3 = s4);1 choiceA. aritamitfalsetrueB. aritarittruetrueC. amitamitfalsefalseD. aritarittruefalseQuestion 12Given:What will happen if you compile/run the following code?class MyClassint x;MyClass(int i)x = i;public static void main(String args)MyClass m1 = new MyClass(100);MyClass m2 = new MyClass(100);System.out.println(m1=m2);if(m1.equals(m2)System.out.println(Both are equal);elseSystem.out.println(Both are not equal);1 choiceA. Compilation error: equals() method was not defined.B. true Both are equalC. false Both are equal.D. true Both are not equal.E. false Both are not equalQuestion 131. public class test 2. public static void add3 (Integer i) 3. int val = Value ( );4. val += 3;5. i = new Integer (val);6. 7.8. public static void main (String args ) 9. Integer i = new Integer (0);10. add3 (i);11. system.out.printIn (Value ( );12. 13. )What is the result?A. Compilation will fail.B. The program prints “0”.C. The program prints “3”.D. Compilation will succeed but an exception will be thrown at line 3.Question 14Given:1. public class ConstOver 2. public ConstOver
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 老年人能力评估国家标准题库及答案
- 止血考试题及答案
- 生产车间如何培训新员工快速上岗
- 麻醉科麻醉前评估指导培训教程
- 口腔颌面外科学练习题含答案
- 国开作业儿科护理学-期末考试08参考(含答案)
- 2025全国“安全生产月”知识考试试题及答案
- 2025年高级育婴员试题库+参考答案
- 河北省 自考试题及答案
- 2025年高级经济师考试(农业经济)综合能力测试题及答案
- 高新技术企业申报范本
- 高中高一英语第一次月考试卷分析
- 开荒期间应知及注意事项课件
- NY 5099-2002无公害食品食用菌栽培基质安全技术要求
- GB/T 6462-2005金属和氧化物覆盖层厚度测量显微镜法
- Unit 3 Lesson 3 Memories of Christmas 课件-高一英语北师大版(2019)必修第一册
- GB/T 11352-2009一般工程用铸造碳钢件
- 学生手册正文
- 小学五年级信息技术下册教案-全册
- 高效协同课件
- 【教材解读】语篇研读-Comfort food
评论
0/150
提交评论