Given:
1. class X {
2. private Y y;
3. public X(Y y) { this.y = y; }
4. }
5. class Y {
6. private X x;
7. public Y() { }
8. public Y(X x) { this.x = x; }
9. }
The instance variable y is intended to represent the composition relationship “X is composed of Y.”
Which code correctly maintains this meaning?
A.
X x1 = new X(new Y());
X x2 = new X(new Y());
B.
X xx = new X(null);
Y y1 = new Y(xx);
Y y2 = new Y(xx);
C.
Y yy = new Y();
X x1 = new X(yy);
X x2 = new X(yy);
D.
Y y1 = new Y(new X(null));
Y y2 = new Y(new X(null));
I did not get this answer. For me A y C are the same. Can someone explain me the difference?