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());
}
}
以及可能的答案:
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
和。要使 MyApp与两者建立关系,必须位于相同的继承树层次结构中。这个对吗?我认为如果一个类将对象作为成员,它会自动建立关系。E
F
Has-A
Employee
Has-A