So far, you have created many class such as Student, Car or Rectangle. You are familiar with the following line:
Rectangle r = new Rectangle ( new Point(3, 4), 10, 20);
In the above line, r is the object variable, which is a variable that points to an object
In the above line, new Point(3, 4) is an object of the Point class. An object can ONLY be created by using the keyword new . Similarly, new Rectangle (new Point(3, 4), 10, 20) is an object of the Rectangle class.
When an object is created, it has to be saved in the computer memory for future use. The location of this object is an internal address, which can be used to locate this object later. This is the object reference. The object reference is stored in the object variable.
What happens when you write "Rectangle s= r;"? do you have two Rectangle objects or one? You only have one object because new is not used. The object reference in variable r is copied in s, so both r and s are pointing to the same object.
B. See slides
C. HW: Answer all questions in Lab 2.