|
Say that A good answer might be:Just one object (and three reference variables, each refering to it.) | ||
The |
|
String strA; // first object String strB; // second object strA = new String( "The Gingham Dog" ); strB = new String( "The Gingham Dog" ); if ( strA.equals( strB ) ) System.out.println( "This WILL print."); if ( strA == strB ) System.out.println( "This will NOT print."); |
In this example, there are two objects (each object has its own identity, so ==
reports false).
Each object contains equivalent data (so equals() reports true).
If you made a Xerox© copy of a sheet of paper, you would have two sheets of paper.