posted 16 years ago
Both will be false.
== will check if two references point to the same object. For instance, if you take a third variable and assign the value of d1 to it (Dog d3 = d1) , then d1 == d3.
equals will use some developer defined comparison. For Strings it is whether or not both Strings have the exact same characters, for Integers it is whether they represent the same int value, but this comparison can easily include many many fields.
However, you as a developer will have to override equals yourself. If you do not, you will inherit the implementation of your parent class. For Dog, that is Object, and Object simply uses == in its check:
Please read the API of Object.equals and Object.hashCode for the exact rules.
[ July 27, 2008: Message edited by: Rob Prime ]