Given:
3. class MyClass { 4. int size;/* www. ja va2 s .c om*/ 5. MyClass(int s) { size = s; } 6. } 7. public class Main { 8. public static void main(String[] args) { 9. MyClass b1 = new MyClass(5); 10. MyClass[] ba = go(b1, new MyClass(6)); 11. ba[0] = b1; 12. for(MyClass b : ba) System.out.print(b.size + " "); 13. } 14. static MyClass[] go(MyClass b1, MyClass b2) { 15. b1.size = 4; 16. MyClass[] ma = {b2, b1}; 17. return ma; 18. } 19. }
What is the result?
A is correct.
Although main()
's b1 is a different reference variable than go()
's b1, they refer to the same MyClass object.