String s1 = new String("abc");
creates the following picture.

A reference is said to "refer to" (or "point to") the object it points to.
For example, if we break the line above into 2 lines,
String s1;
At this point, we only have a reference. This reference points to nowhere, that is, null.
![]()
Then in the next line we instantiate an object by new.
s1 = new String("abc");
Now the picture becomes:

int x; // int variable declared Mortgage m; // Mortgage reference variable declared m = new Mortgage(100000, 5.0, 30); // Mortgage object instantiated
Mortgage m;
do {
m = new Mortgage(...); // Previously instantiated object becomes
// an orphan in heap, but it will be cleaned
// up due to Java's automatic garbage collection.
} while (...);
do {
Mortgage m = new Mortgage(...); // m is declared inside do-while scope
} while (...);
System.out.println(m); // ERROR!! m is out of scope

public boolean equals(Object obj);
For instance, here is an example equals() method for Mortgage:
class Mortgage
{
// fields
private double amount;
private double rate;
private int years;
// methods
public Mortagage() {..}
...
public boolean equals(Object obj)
{
if (obj instanceof Morgage) // if parameter obj is of type Mortage
{
Mortgage mo = (Mortgage) obj; // type-cast obj to Morgage
return (this.amount == mo.amount && // private access in mo is ok
this.rate == mo.rate && // because mo is Mortage too
this.years == mo.years); // (by type-casting above).
}
else
return false; // false if comparing with object of other type
}
}