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. publ

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899559
Joined: Mon Aug 02, 2021 8:13 am

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. publ

Post by answerhappygod »

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));
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!

This question has been solved and has 1 reply.

You must be registered to view answers and replies in this topic. Registration is free.


Register Login
 
Post Reply