Click the Exhibit button. 10. class Inner { 11. private int x; 12. public void setX( int x) { this.x = x; } 13. public int getX() { return x; } 14. } 15. 16. class Outer { 17. private Inner y; 18. public void setY( Inner y) { this.y = y; } 19. public Inner getY() { return y; } 20. } 21. 22. public class Gamma { 23. public static void main( String[] args) { 24. Outer o = new Outer(); 25. Inner i = new Inner(); 26.int n=10; 27. i.setX(n); 28. o.setY(i); 29. // insert code here 30. System.out.println( o.getY().getX()); 31. } 32. } Which three code fragments, added individually at line 29, produce the output 100? (Choose three.)

  1. n = 100;

  2. i.setX( 100);

  3. o.getY().setX( 100);

  4. i = new Inner(); i.setX( 100);

  5. o.setY( i); i = new Inner(); i.setX( 100);

  6. i = new Inner(); i.setX( 100); o.setY( i);


Correct Option: B,C,F

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) n = 100; - This option is incorrect because it assigns the value of 100 to the variable n, but it does not modify the value of x in the Inner object i that is stored in the Outer object o.

Option B) i.setX(100); - This option is correct because it directly sets the value of x in the Inner object i to 100.

Option C) o.getY().setX(100); - This option is correct because it first retrieves the Inner object i stored in the Outer object o using the getY() method, and then sets the value of x in the Inner object to 100 using the setX() method.

Option D) i = new Inner(); i.setX(100); - This option is incorrect because it creates a new Inner object i and sets its value of x to 100, but it does not update the Inner object that is stored in the Outer object o.

Option E) o.setY(i); i = new Inner(); i.setX(100); - This option is incorrect because it first sets the Inner object i as the value of y in the Outer object o, but then it creates a new Inner object i and sets its value of x to 100. This new Inner object is not stored in the Outer object o.

Option F) i = new Inner(); i.setX(100); o.setY(i); - This option is correct because it first creates a new Inner object i and sets its value of x to 100. Then, it sets this Inner object as the value of y in the Outer object o.

The correct answers are B, C, and F. These options modify the value of x in the Inner object i that is stored in the Outer object o, resulting in the output of 100 when o.getY().getX() is called at line 30.

Find more quizzes: