This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes equals and this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "equals and this" Watch "equals and this" New topic

equals and this

srinivas sridaragaddi
Ranch Hand

Joined: Jul 24, 2007
Posts: 225

output: objects are different

where as i was expecting objects are same can anyone explain me
as to why it is generating this output?

SCJP 5.0<br /> <br />"Skills are started with learning and mastered with improvement. Nothing is hereditary except death" BUDDHA...
Gautam Pandey

Joined: Sep 21, 2007
Posts: 21
since equals method is not overidden in MyClass , it uses the Object's equals version which returns true on if the objects are referring to the same object. Since in your case its creating two different objects , it returns false.
I agree. Here's the link:
subject: equals and this
It's not a secret anymore!