Which four statements are true? (Choose four.)
A. Has-a relationships should never be encapsulated.
B. Has-a relationships should be implemented using inheritance.
C. Has-a relationships can be implemented using instance variables.
D. Is-a relationships can be implemented using the extends keyword.
E. Is-a relationships can be implemented using the implements keyword.
F. The relationship between Movie and Actress is an example of an is-a relationship.
G. An array or a collection can be used to implement a one-to-many has-a relationship.
答案:CDEG A是什么意思?
A. Has-a relationships should never be encapsulated.
B. Has-a relationships should be implemented using inheritance.
C. Has-a relationships can be implemented using instance variables.
D. Is-a relationships can be implemented using the extends keyword.
E. Is-a relationships can be implemented using the implements keyword.
F. The relationship between Movie and Actress is an example of an is-a relationship.
G. An array or a collection can be used to implement a one-to-many has-a relationship.
答案:CDEG A是什么意思?
解决方案 »
- 求SCJP的的中、英文教程 不胜感激
- 请问 这里 @version %I%, %G% 的 %I%, %G% 是什么意思啊?
- Scanner 里面有没有nexChar()方法呀?
- tomcat申请证书,并认证了证书,但是还是通不过,高手来,解决了,再多给分
- Applet中如何添加JList控件(初学者)
- 急求:表达式求值问题!!在线急等!
- BigInteger(byte[] b)它返回是一个数值还是一个数组?
- 大神看看为啥输入框,也就是jftext,没有显示?
- 有谁知道取当前点颜色的函数是什么啊
- 请教用java从properties文件中读取属性字段的方法?
- java 中如何打包一个文件为zip
- 新手问题:类和对象
B.Has-a relationships should be implemented using inheritance.(has-a关系应该用继承来实现)
C.Has-a relationships can be implemented using instance variables.(has-a关系可以用实例变量来实现)
D.Is-a relationships can be implemented using the extends keyword. (is-a关系可以用extends关键词实现)
E.Is-a relationships can be implemented using the implements keyword.(is-a关系可以用implements关键词来实现)
F.The relationship between Movie and Actress is an example of an is-a relationship.(电影与女演员的关系是一种is-a关系)
G.An array or a collection can be used to implement a one-to-many has-a relationship.(数组或集合类可以用来实现一对多的is-a关系)
is-a关系是多态的一种关系,可以说子类对象是一个(is a)父类对象,或者实现某个接口的类是一个(is a)该接口的对象
有此来看:
A错:has-a关系常常被封装
B错:应该说is-a关系可以用继承来实现
C,D,E对
F错:Movie类与actress属于has-a关系
G对
例如有一个Test类继承Object并且实现Runnable接口
class Test extends Object implements Runnable
那么下面两个语句都是成立的:
Object test1 = new Test();
Runnable test2 = new Test();
因为一个Test对象,既可以说他是一个Object对象,也可以说他是一个Runnable对象
A选项原话意思是:has-a的关系,不应该被封装,换句话说就是,类不应该封装类的成员变量(并不是说不应该使用has-a这种模式)
而事实上,A选项原话那种说法是错误的,类的成员变量通常都是需要被封装的,具体来说就是用private来修饰