class Employee {
private String name;
void setName(String n) { name = n; }
String getName() { return name; }
}
interface Mungeable {
void doMunging();
}
public class MyApp implements Mungeable {
public void doMunging() { ; }
public static void main(String[] args) {
Employee e = new Employee();
e.setName("bob");
System.out.print(e.getName());
}
}
和可能的答案:待办事项类都必须是在同一个继承树让他们有一个拥有-A的关系
Which are true? (Choose all that apply.)
A. MyApp is-a Employee.
B. MyApp is-a Mungeable.
C. MyApp has-a Employee.
D. MyApp has-a Mungeable.
E. The code is loosely coupled.
F. The Employee class is well encapsulated.
在回答上述问题,我选择的选项B
,C
,E
和F
显然唯一正确的答案是B
,E
和F
。对于MyApp与Employee
有Has-A
关系,它们都必须位于同一继承树层次结构中。它是否正确?我认为,如果一个班级将该对象作为成员,它就会自动产生Has-A
关系。
这是功课吗?如果是,请标记为这样。 – tobiasbayer 2012-01-02 16:45:59
不,它不是作业 – ziggy 2012-01-02 16:46:37
好吧。谢谢大家的回复。 – ziggy 2012-01-02 16:56:27