云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > SCJP题库 Module3 - 图文

SCJP题库 Module3 - 图文

  • 62 次阅读
  • 3 次下载
  • 2025/6/22 18:15:31

relationship.

G. An array or a collection can be used to implement a one-to-many has-a relationship.

Answer: CDEG 仔细研究研究,挺费脑袋

Question 29

Which two are true about has-a and is-a relationships? (Choose two.) A. Inheritance(继承) represents 表现, an is-a relationship. B. Inheritance represents a has-a relationship.

C. Interfaces must be used when creating a has-a relationship.

D. Instance 引用变量variables can be used when creating a has-a relationship. Answer: AD 同上

Question 30 Given:

10. interface Jumper { public void jump(); } ......20. class Animal {}

......30. class Dog extends Animal { 31. Tail tail; 32. }

......40. class Beagle extends Dog implements Jumper { 41. public void jump() { } 42. }.......

50. class Cat implements Jumper { 51. public void jump() { } 52. }

Which three are true? (Choose three.) A. Cat is-a Animal B. Cat is-a Jumper C. Dog is-a Animal D. Dog is-a Jumper E. Cat has-a Animal F. Beagle has-a Tail G. Beagle has-a Jumper

Answer: BCF 仔细分析,骂了隔壁的

Question 31 Given:

1. package geometry;

2. public class Hypotenuse {

3. public InnerTriangle it = new InnerTriangle();

4. class InnerTriangle { 内部类是default类型的,作用域是本包!如果是public的就可以随便调用了!!! 5. public int base; 6. public int height; 7. } 8. }

Which is true about the class of an object that can reference the variable base?

A. It can be any class.

B. No class has access to base.

C. The class must belong(属于) to the geometry package.

13

D. The class must be a subclass of the class Hypotenuse. Answer: C

二、拖拽题: Question 1:

Answer:

class A has name A class B has name A

Question 2:

Place the Output Options in the Actual(现实的) Output Sequence to indicate(指示,显示) the output from this code.

14

Answer:

Alpha:foo Beta:foo Beta:bar Beta:bar

Alpha:foo,这个答案我做错了,必须注意一下,下面是测试代码,还有解释,下次看到这的时候重点看看

解释: 仔细看这段代码Alpha中的foo方法和Beta中的foo方法,一个是可变长,一个是定长,那么两者之间就属于完全不一样的方法

也就是说不存在覆盖关系,那么也就是没有多态性表现了,所以当调用a.foo(“test”);的时候,直接调用的就是Alpha中的foo

方法。如果Alpha中也有一个foo(String a)方法的话,那么就是和子类中的一样了,也就存在多态行,那么结果则调用的是子类

中的foo方法!

代码:

class Alpha {

public void foo(String...args){ //注意这个方法,可变长的参数类型

System.out.print(\); }

public void bar(String a) {

System.out.print(\); } }

public class Beta extends Alpha{

public void foo(String a){ //注意这个方法,定长的参数类型

System.out.print(\); }

public void bar(String a) {

System.out.print(\); }

public static void main(String[] args) { Alpha a = new Beta(); Beta b = (Beta)a;

15

a.foo(\这句出现了问题,其他都做对了 b.foo(\); a.bar(\); b.bar(\); } }

Question 3:

Answer:

public class Beta extends Alpha{ public void bar(int x){}

public int bar(String x){return 1;} public void bar(int x,int y){} }

无争议!

但是在这里总结一下关于当覆盖方法时候的范围问题:权限,返回类型,异常

权限:子类方法的修饰符不能比父类的更窄。eg:父类是public的,但是子类的是private的,就不可以

返回类型:子类方法的返回类型可以和父类相同或者是父类返回类型的子类型。 异常:子类方法抛出的异常可以和父类相同或者是父类抛出异常类型的子类型。

Question 4:

Place the Relations on their corresponding(对应) Implementation Structures(结构).

Note: Not all Implementation Structures will be used.

16

搜索更多关于: SCJP题库 Module3 - 图文 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

relationship. G. An array or a collection can be used to implement a one-to-many has-a relationship. Answer: CDEG 仔细研究研究,挺费脑袋 Question 29 Which two are true about has-a and is-a relationships? (Choose two.) A. Inheritance(继承) represents 表现, an is-a relationship. B. Inheritance represents a has-a relationship. C. Interfaces must be used when creating a has-a

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com