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是什么意思?

解决方案 »

  1.   

    A.Has-a relationships should never be encapsulated.(has-a关系不应该被封装)
    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关系)
      

  2.   

    has-a关系是一种类与类的成员变量之间的关系,假设有一个Movie类,其中有一个actress的成员变量,那么就可以说Movie类有一个(has a)actress成员变量
    is-a关系是多态的一种关系,可以说子类对象是一个(is a)父类对象,或者实现某个接口的类是一个(is a)该接口的对象
    有此来看:
    A错:has-a关系常常被封装
    B错:应该说is-a关系可以用继承来实现
    C,D,E对
    F错:Movie类与actress属于has-a关系
    G对
      

  3.   

    has-a封装是怎么封装的?另外我觉得DE不是互相矛盾了吗?实现接口也能叫is a ?
      

  4.   

    has-a关系就是类与类的成员变量之间的关系,用private来修饰类的成员变量是封装的一种手段,这样一来,外部就无法知道这个类有哪些成员变量,也无法直接访问或者操作这些成员变量,只能通过public的方法去操作,这就达到了封装的效果D和E是同时成立的,is a的关系既可以用继承来实现,也可以用接口来实现
    例如有一个Test类继承Object并且实现Runnable接口
    class Test extends Object implements Runnable
    那么下面两个语句都是成立的:
    Object test1 = new Test();
    Runnable test2 = new Test();
    因为一个Test对象,既可以说他是一个Object对象,也可以说他是一个Runnable对象
      

  5.   

    照你说,A的意思就是说不应该使用has-a这种模式了吧。
      

  6.   

    A.Has-a relationships should never be encapsulated.
    A选项原话意思是:has-a的关系,不应该被封装,换句话说就是,类不应该封装类的成员变量(并不是说不应该使用has-a这种模式)
    而事实上,A选项原话那种说法是错误的,类的成员变量通常都是需要被封装的,具体来说就是用private来修饰