



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Chapter 14 Abstract Classes and Interfaces1.E and F2. The benefits are for generic programming. A variable of GeometricObject type can use the getArea and getPerimeter methods at compilation time.3.True4.d.5.True6. Using Comparable as the parameter type is simpler and more robust than using Object.7. The benefits are for generic programming. A variable of the class that implements Comparable can be passed to a method that requires a Comparable type.8. True9. No. Yes, the Date class implements Cloneable.10. If the CloneableCircle class does not override the clone() method, the program would receive a syntax error because clone() is protected in java.lang.Object. If CloneableCircle does not implement java.lang.Cloneable in Line 31, the program would receive a runtime error because c2 would be null in Line 7.11. truefalsetrue12. truefalselist is New York, Atlantalist1 is New York, Atlantalist2.get(0) is New Yorklist2.size() is 113. A syntax error is reported because clone() is protected in Object. To enable cloning, do two things: (1) override clone() in the class for the object to be cloned; (2) implement java.lang.Cloneable for the class.14.See the example in the text in the section on Interfaces vs. Abstract Classes.15.See the section Processing Primitive Type Values as Objects. These classes are useful when passing numerical values as objects.16.Integer i = new Integer(23);Answer: CorrectInteger i = new Integer(23);Answer: CorrectInteger i = Integer.valueOf(23);Answer: Correct Integer i = Integer.parseInt(23,8);Answer: IncorrectDouble d = new Double();Answer: Incorrect, no default constructor in DoubleDouble d = Double.valueOf(23.45);Answer: Correctint i = (Integer.valueOf(23).intValue();Answer: Correctdouble d = (Double.valueOf(23.4).doubleValue();Answer: Correctint i = (Double.valueOf(23.4).intValue();Answer: CorrectString s = (Double.valueOf(23.4).toString();Answer: Correct17. Use new Integer(int).toString() to convert an integer to a string. Use new Double(double).toString() to convert a double to a string.18. At runtime, JVM attempts to convert numberRef to a Double object, but numberRef is an instance of Integer, not Double.19. numberArray0is of the Integer type.20. The program has a syntax error because x does not have the compareTo method.21. The program has a syntax error because the member access operator (.) is executed before the casting operator.22.10101611111723.Number x = 3; / Correct, this is same as x = new Integer(3)Integer x = 3; / CorrectDouble x = 3; / Wrong, this is same as Double x = new Integer(3)Double x = 3.0; / Correctint x = new Integer(3); / Correctint x = new Integer(3) + new Integer(4); / Correctdouble y = 3.4; Value(); / WrongJOptionPane.showMessageDialog(null, 45.5); / Correct. You can pass a primitive type value wherever an object is required.24.new int10 cannot be assigned to into a variable of Object type, but new String100, new Object50, or new Calendar20 are fine.25. The output is 3. Please note that BigInteger and BigDecimal are immutable.26. Find these terms in this chapter.27.Indicate true or false for the following statements:1.An abstract class can have instances created using the constructor of the abstract class.Answer: No, but an instance of its concrete subclass is also an instance of the parent abstract class. You cannot create an object using the constructor of the abstract class. However, you can create an object using a concrete subclass of the abstract class. This object is an instance of the subclass and it is also an instance of the abstract class.2.An abstract class can be extended.Answer: True3.An interface can be a separate unit and can be compiled into a bytecode file.Answer: True4 A subclass of a non-abstract superclass cannot be abstract. Answer: False5 A subclass cannot override a concrete method in a superclass to declare it abstract.Answer: False, This is rare, but useful when the implementation of the method in the superclass becomes invalid in the subclass. In this case, the subclass must be declared abstract. 6.An abstract method must be non-staticAnswer: True7 An interface
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 四川省成都市高三摸底考试(零诊)数学试题
- 河南省部分重点高中2024-2025学年高二下学期5月调研生物试题(解析版)
- 卫生管理实施方案(3篇)
- 乡镇酒店定价方案(3篇)
- 企业劳务避税方案(3篇)
- 法院大楼设计方案(3篇)
- 塔吊出租纠纷处理方案(3篇)
- 2025年皮下注射技术试题(附答案)
- 2025年医院感染知识竞赛试题(附答案)
- 全民核酸检测培训知识课件
- 麦当劳-标准化管理
- 法国西电MICS中文操作说明书
- 第9章探放水钻机及相关设备的安全使用.
- (高清正版)JJF 1908-2021 双金属温度计校准规范
- 交通部农村公路建设标准指导意见
- 卫浴店面管理
- 清表施工方案4常用
- 纯化水系统再验证方案E
- 5立方米液化石油气储罐课程设计说明书
- 临床技术操作规范_骨科学分册资料全
- 华为内部虚拟股管理暂行条例
评论
0/150
提交评论