wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Objects equal method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Objects equal method" Watch "Objects equal method" New topic
Author

Objects equal method

kish kumar
Ranch Hand

Joined: Jan 03, 2008
Posts: 54

The description of Object class equal method says for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).



The above code displays true. o1 and o2 refer 2 different objects. inside equals method we have code "return this==obj" .when o1 and o2 refer different objects == should return false. but why i am getting true?

how the equals method of object different from equals method of String?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

The Integer class overrides the equals method.


[My Blog]
All roads lead to JavaRanch
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

how the equals method of object different from equals method of String?


Di you mean to say equals() method of Integer ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
kish kumar
Ranch Hand

Joined: Jan 03, 2008
Posts: 54

equlas method of object vs equlas method of string
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

kish kumar wrote:
equlas method of object vs equlas method of string


I noticed that you are comparing Integers in your code snippet, which is why I asked.

This is the equals implementation of String



And this is the implementation for Object.java




And for Integer.java we have

kish kumar
Ranch Hand

Joined: Jan 03, 2008
Posts: 54
Thanks for the replies
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Objects equal method
 
Similar Threads
Equals and ==
Equals and == with Objects Problem
Question regarding Map interface
Arrays comparsion: int[].equals() vs Arrays.equals()
hashCode and equals