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