posted 19 years ago
Probably a beginner question, but here goes:
(obj1 == obj2) returns true if and only if obj1 is the same object as obj2.
Think of two cars -- myCar and yourCar. (myCar == yourCar) is true if there is actually only one physical car there. It doesn't matter if we both drive identical puke green 1972 Oldsmobiles, they are still not the same car, so they won't be ==.
There is a method called equals() defined in the Object class that should be overridden for cases in which you want to see if the two cars are the same, for instance if you want to determine the value of a car, they would be equal (if we leave out a lot of details) even if they don't have the same VIN or color.
So, the short answer is, you can compare objects with equals() and references to objects with ==