13. |
R1. Object References
You should be able to answer the following two questions without writing programs. If you like, you can write small test programs to double-check your answers.
Recall that the translate method of the Rectangle class moves a rectangle by a certain amount. For example,
Rectangle r = new Rectangle(5, 10, 20, 30); r.translate(10, 15); System.out.println(r); // prints Rectangle[x=15,y=25,width=20,height=30]
When you copy an object variable, the copy is simply a second reference to the same object.
Consider this program segment:
Rectangle square = new Rectangle(0, 0, 100, 100); Rectangle r2 = square; r2.translate(10, 15); System.out.println(r2); System.out.println(square);
What is the output of this code?
Answer:
|