ImageVerifierCode 换一换
格式:DOC , 页数:15 ,大小:99.50KB ,
资源ID:1336862      下载积分:5000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-1336862.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(【计算机类职业资格】计算机Java认证-理解类继承、理解多态和类型转换及答案解析.doc)为本站会员(王申宇)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

【计算机类职业资格】计算机Java认证-理解类继承、理解多态和类型转换及答案解析.doc

1、计算机 Java认证-理解类继承、理解多态和类型转换及答案解析(总分:84.96,做题时间:90 分钟)一、B不定项选择题/B(总题数:2,分数:85.00)Refer to this class for the following two questions.public class Account private int money;public int getMoney() return this.money;public void setMoney(int money) this.money = money;(分数:48.96)(1).In the code segment, what

2、 is the method getMoney() considered? A. Get method B. Access method C. Getter method D. Instance Variable method(分数:3.06)A.B.C.D.(2).In the code segment, what is the method setMoney (int money) considered? A. Set method B. Access method C. Setter method D. Instance variable method(分数:3.06)A.B.C.D.(

3、3).Which of the following defines information hiding? A. Information hiding is hiding as much detail about your class as possible so others cant steal it. B. Information hiding is about hiding implementation details and protecting variables from being used the wrong way. C. Information hiding is use

4、d to obscure the interworking of your class so external classes must use the public interface.(分数:3.06)A.B.C.D.(4).What access modifier is used to make the instance variable or method available only to the class in which it is defined? A. public B. private C. protected D. package-private (default)(分

5、数:3.06)A.B.C.D.(5).What access modifier is used for methods that were defined in an interface? A. public B. private C. protected D. package-private (default)(分数:3.06)A.B.C.D.(6).What is the proper signature for class X if it inherits class Z? A. public class X inherits Z. B. public class X extends Z

6、 C. public class X implements Z.(分数:3.06)A.B.C.D.(7).How many classes can a class extend directly? A. Zero B. One C. Two D. As many as it needs(分数:3.06)A.B.C.D.(8).How many interfaces can a class implement directly? A. Zero B. One C. Two D. As many as it needs(分数:3.06)A.B.C.D.(9).Consider the follo

7、wing UML illustration for assistance with this question: What is the proper signature for class A if it implements interfaces B and C?(分数:3.06)A.B.C.D.(10).Consider the following UML illustration for assistance with this question: What is the proper signature for interface I to inherit interfaces J

8、and K?(分数:3.06)A.B.C.D.(11).Which statement is true about the term polymorphism? A. It is a Latin word that roughly means “changeable.“ B. It is a Greek word that roughly means “many forms.“ C. It is an old English word that roughly means “insectlike.“ D. It is a new technical term that means “Java

9、object.“(分数:3.06)A.B.C.D.(12).What type of object can polymorphically behave as another? A. An object can act as any subclass of the class it was created from. B. An object can act as any superclass of the class it was created from. C. An object can act as any other abstract class.(分数:3.06)A.B.C.D.(

10、13).Polymorphism helps to facilitate which of the following? (Choose all that apply.) A. Highly optimized code B. Code reuse C. Code obfuscation D. Code that is genetic and flexible(分数:3.06)A.B.C.D.(14).What is a correct “is-a“ relationship? A. A specific object “is-a“ more generic one. B. A genetic

11、 object “is-a“ more specific one. C. A null object “is-an“ object.(分数:3.06)A.B.C.D.(15).Which of the following statements explain why an object can polymorphically behave as an interface? A. By implementing the interface, the object is required to have all of the functionality that the interface rep

12、resents. B. By implementing the interface, the object inherits all the required methods it defines. C. An object can behave as an interface because interfaces do not have a strict expected behavior and therefore any object can act as an interface.(分数:3.06)A.B.C.D.(16).What does it mean if a develope

13、r is programming to an interface? A. The developer is implementing an interface for the class he or she is working on. B. The developer was given a set of interfaces he or she must implement. C. The developer is defining the functionality instead of strict object types as much as possible.(分数:3.06)A

14、B.C.D.The Drivable interface:public interface Drivable /* Drivable definitions*/The Tractor class:public class Tractor implements Drivable /* Tractor functionality*/The Vehicle class:public class Vehicle /* Vehicle functionality*/The Car class:public class Car extends Vehicle implements Drivable /*

15、 Car functionality*/The Truck class:public class Truck extends Vehicle implements Drivable /* Truck functionality*/(分数:36.00)(1).Given the preceding classes and interface, would the following code segment produce errors when compiled? Car car = new Car(); Vehicle vehicle = car; A. No errors would be

16、 produced. B. This code would result in compile errors.(分数:4.00)A.B.C.D.(2).Given the preceding classes and interface, would the following code segment produce errors when compiled? Truck truck = new Truck(); Drivable drivable = truck; A. No errors would be produced. B. This code would result in com

17、pile errors.(分数:4.00)A.B.C.D.(3).Given the preceding classes and interface, would the following code segment produce errors when compiled? Tractor tractor = new Tractor(); Vehicle vehicle = tractor; A. No errors would be produced. B. This code would result in compile errors.(分数:4.00)A.B.C.D.(4).Give

18、n the preceding classes and interface, would the following code segment produce errors when compiled? Drivable drivable = new Drivable(); Truck truck = drivable; A. No errors would be produced. B. This code would result in compile errors.(分数:4.00)A.B.C.D.(5).Given the preceding classes and interface

19、 would the following code segment produce errors when compiled? Vehicle vehicle = new Vehicle(); Object o = vehicle; A. No errors would be produced. B. This code would result in compile errors.(分数:4.00)A.B.C.D.(6).Given the preceding classes and interface, would the following code segment produce e

20、rrors when compiled? Truck truck = new Truck(); Object o = truck; A. No errors would be produced. B. This code would result in compile errors.(分数:4.00)A.B.C.D.(7).In what cases is casting needed? (Choose all that apply.) A. Going from a superclass to subclass B. Going from a subclass to superclass C

21、 Using an int as a double D. Using a float as a long(分数:4.00)A.B.C.D.(8).Why must the a variable be casted? A. So future developers understand the intended use of the variable B. To tell the compiler that the data conversion is safe to make C. Because it was used polymorphically before(分数:4.00)A.B.

22、C.D.(9).What would cause an exception to be thrown from a cast? A. If precision is lost due to the cast B. If the object is cast to a superclass of its current type C. If the object was never instantiated as the object that it is being cast to or one of its subclasses D. If the object is being cast

23、is null(分数:4.00)A.B.C.D.计算机 Java认证-理解类继承、理解多态和类型转换答案解析(总分:84.96,做题时间:90 分钟)一、B不定项选择题/B(总题数:2,分数:85.00)Refer to this class for the following two questions.public class Account private int money;public int getMoney() return this.money;public void setMoney(int money) this.money = money;(分数:48.96)(1).In

24、 the code segment, what is the method getMoney() considered? A. Get method B. Access method C. Getter method D. Instance Variable method(分数:3.06)A.B.C. D.解析:这是一个 getter方法。getter 方法用于获取一个 private的实例变量。getter 方法的名字总是get后紧跟以大写字母开头的变量名。如果变量是一个 boolean类型,则 get被替代为 is。A、B 和 D都不正确,并且它们不是典型的 Java术语。(2).In t

25、he code segment, what is the method setMoney (int money) considered? A. Set method B. Access method C. Setter method D. Instance variable method(分数:3.06)A.B.C. D.解析:这是一个 setter方法。setter 方法用于设置一个 private的实例变量。setter 方法的名字总是set后紧跟以大写字母开头的变量名。它们需要一个参数并且使用它来设置变量。A、B 和 D都不正确,并且不是典型的 Java术语。(3).Which of t

26、he following defines information hiding? A. Information hiding is hiding as much detail about your class as possible so others cant steal it. B. Information hiding is about hiding implementation details and protecting variables from being used the wrong way. C. Information hiding is used to obscure

27、the interworking of your class so external classes must use the public interface.(分数:3.06)A.B. C.D.解析:好的类设计尽可能多地隐藏方法和实例变量。这是通过使用 private访问修饰符来完成的。这就是为什么外部对象不要试图以开发者不期望的方式与对象进行交互。隐藏信息使得代码更易于维护和更模块化。A 和 C不正确。A 不正确,因为信息隐藏与代码保护没有关系。C 不正确,因为访问修饰符应该用于强制外部类使用合适的公共接口。(4).What access modifier is used to make

28、 the instance variable or method available only to the class in which it is defined? A. public B. private C. protected D. package-private (default)(分数:3.06)A.B. C.D.解析:private 访问修饰符用于只允许类中的方法访问方法或者实例变量。A、C 和 D不正确。A 不正确,因为 public将使实例变量对所有类都可见。C 不正确,因为 protected将使实例变量对所有子类或者同一包中的任何类都可见。D 不正确,因为包私有的或者默

29、认的访问级别,将使实例变量对同一包中的任何其他类可见。(5).What access modifier is used for methods that were defined in an interface? A. public B. private C. protected D. package-private (default)(分数:3.06)A. B.C.D.解析:当实现接口的方法时,使用 public访问修饰符。B、C 和 D不正确。因为它们限制了方法的可访问性,因此不适合于一个接口。(6).What is the proper signature for class X if

30、it inherits class Z? A. public class X inherits Z. B. public class X extends Z. C. public class X implements Z.(分数:3.06)A.B. C.D.解析:extends 关键字用于继承一个类。A 和 C不正确。A 不正确,因为 inherits不是有效的 Java关键字。C 不正确,因为 implements关键字用于接口,而不是类。(7).How many classes can a class extend directly? A. Zero B. One C. Two D. As

31、 many as it needs(分数:3.06)A.B. C.D.解析:一个类只能扩展一个其他类。但是,它可以使一个类扩展一个又扩展了另一个类的类,以此类推。A、C 和 D不正确。(8).How many interfaces can a class implement directly? A. Zero B. One C. Two D. As many as it needs(分数:3.06)A.B.C.D. 解析:类可以按需实现多个接口。A、B 和 C不正确。(9).Consider the following UML illustration for assistance with

32、this question: What is the proper signature for class A if it implements interfaces B and C?(分数:3.06)A.B. C.D.解析:类使用关键字 implements来实现一个接口。要实现多个接口,则接口应该出现在关键字implements后以逗号分隔的列表中。A、C、D 和 E不正确。A 不正确,因为 implements关键字不应该被包括多次。C 不正确,因为应该使用 implements关键字而不是 interface,并且它只应该使用一次。D 不正确,因为应该使用 implements而不是

33、interface。E 不正确,因为 extends用于类,而不是接口;应该使用 implements替代。(10).Consider the following UML illustration for assistance with this question: What is the proper signature for interface I to inherit interfaces J and K?(分数:3.06)A. B.C.D.解析:接口也可以继承其他接口。不同于类,接口可以按照需要继承或者扩展多个接口。接口使用关键字extends,紧跟逗号分隔的一个列表,列出该接口希望

34、扩展的所有其他接口。B、C 和 D不正确。B 不正确,因为只有类实现接口。一个接口扩展其他接口。C 不正确,因为应该使用 extends,并且只能用一次。D不正确,因为没有正确使用 interface关键字。(11).Which statement is true about the term polymorphism? A. It is a Latin word that roughly means “changeable.“ B. It is a Greek word that roughly means “many forms.“ C. It is an old English word

35、 that roughly means “insectlike.“ D. It is a new technical term that means “Java object.“(分数:3.06)A.B. C.D.解析:多态这个单词来源于希腊语,意思为“多种形式”。A、C 和 D不正确。(12).What type of object can polymorphically behave as another? A. An object can act as any subclass of the class it was created from. B. An object can act

36、as any superclass of the class it was created from. C. An object can act as any other abstract class.(分数:3.06)A.B. C.D.解析:对象继承了其超类的所有功能,因此可以多态地具有它们的行为。A 和 C不正确。A 不正确,因为对象不能用作其子类,因为子类更具体并且包含父类中不存在的功能。C 不正确,因为这些类之间需要有“is-a”关系。这个答案没有提及是什么关系。(13).Polymorphism helps to facilitate which of the following?

37、Choose all that apply.) A. Highly optimized code B. Code reuse C. Code obfuscation D. Code that is genetic and flexible(分数:3.06)A.B. C.D. 解析:多态有助于创建可重用的代码,因为它允许代码可以编写得更抽象,因此 B正确。类似于 B,通过使用任何更具体对象都可以满足的通用数据类型,多态使得代码更通用。因此,D 也正确。A 和 C不正确。A不正确,因为多态对代码优化方面没有影响。C 不正确,因为混淆代码(目的是让代码难以阅读)与多态无关。(14).What is

38、 a correct “is-a“ relationship? A. A specific object “is-a“ more generic one. B. A genetic object “is-a“ more specific one. C. A null object “is-an“ object.(分数:3.06)A. B.C.D.解析:一个更具体的对象可以被看成是一个更通用的对象。这是多态的基本原则。B 和 C不正确。B 不正确,因为通用对象不具有更具体对象的所有功能,因此与具体的对象不具备“is-a”关系。C 不正确,因为一个 null对象对它与其他对象间的关系没有影响。(1

39、5).Which of the following statements explain why an object can polymorphically behave as an interface? A. By implementing the interface, the object is required to have all of the functionality that the interface represents. B. By implementing the interface, the object inherits all the required metho

40、ds it defines. C. An object can behave as an interface because interfaces do not have a strict expected behavior and therefore any object can act as an interface.(分数:3.06)A. B.C.D.解析:当类实现一个接口时,它需要实现接口包含的所有方法。这给予类在接口中定义的功能。因此允许该类用作接口。B 和 C不正确。B 不正确,因为当接口被实现时,没有继承任何东西。C 不正确,因为每一个接口都有严格的行为预期。这由必须实现的方法来

41、表示。(16).What does it mean if a developer is programming to an interface? A. The developer is implementing an interface for the class he or she is working on. B. The developer was given a set of interfaces he or she must implement. C. The developer is defining the functionality instead of strict obje

42、ct types as much as possible.(分数:3.06)A.B.C. D.解析:面向接口编程意味着开发者定义功能来代替对象数据类型。然后任何对象都可以实现所需要的接口,并使用它。如果不使用接口,则只能使用定义的特定的数据类型对象。A 和 B不正确。A 不正确,因为面向接口编程与只在类中实现接口相比是一个更大的概念。B 不正确,因为在这种情形下,开发者只是实现了预先确定的一组接口。The Drivable interface:public interface Drivable /* Drivable definitions*/The Tractor class:public

43、class Tractor implements Drivable /* Tractor functionality*/The Vehicle class:public class Vehicle /* Vehicle functionality*/The Car class:public class Car extends Vehicle implements Drivable /* Car functionality*/The Truck class:public class Truck extends Vehicle implements Drivable /* Truck functi

44、onality*/(分数:36.00)(1).Given the preceding classes and interface, would the following code segment produce errors when compiled? Car car = new Car(); Vehicle vehicle = car; A. No errors would be produced. B. This code would result in compile errors.(分数:4.00)A. B.C.D.解析:不会产生错误,因为 Car类扩展了 Vehicle类,因此可

45、以用作一个 Vehicle对象。B 不正确。(2).Given the preceding classes and interface, would the following code segment produce errors when compiled? Truck truck = new Truck(); Drivable drivable = truck; A. No errors would be produced. B. This code would result in compile errors.(分数:4.00)A. B.C.D.解析:不会产生错误,因为 Truck类实

46、现了 Drivable接口,因此可以用作一个 Drivable对象。B 不正确。(3).Given the preceding classes and interface, would the following code segment produce errors when compiled? Tractor tractor = new Tractor(); Vehicle vehicle = tractor; A. No errors would be produced. B. This code would result in compile errors.(分数:4.00)A.B.

47、C.D.解析:这段代码将会导致编译错误,因为 Vehicle类不是 Tractor类的超类。A 不正确。(4).Given the preceding classes and interface, would the following code segment produce errors when compiled? Drivable drivable = new Drivable(); Truck truck = drivable; A. No errors would be produced. B. This code would result in compile errors.(分

48、数:4.00)A.B. C.D.解析:这段代码会导致编译错误,因为 Drivable是一个接口,它不能被实例化。A 不正确。(5).Given the preceding classes and interface, would the following code segment produce errors when compiled? Vehicle vehicle = new Vehicle(); Object o = vehicle; A. No errors would be produced. B. This code would result in compile errors.(分数:4.00)A. B.C.D.解析:不会产生错误,因为 Vehicle类不是具体类,并且 Object类是每个 Java对象的超类。B 不正确。(6).Given the preceding classes and interface, would the following code segment produce errors when compiled? Truck truck = new Truck(); Object o = truck; A. No errors would be produced. B. This code would re

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1