jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes equals() and hascode() doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "equals() and hascode() doubt" Watch "equals() and hascode() doubt" New topic

equals() and hascode() doubt

roberto nasel

Joined: Sep 09, 2007
Posts: 1
Hi all!
I am new to this.

may I know why if or else of equals method is not printing?
correct me

Henry Wong

Joined: Sep 28, 2004
Posts: 20517

may I know why if or else of equals method is not printing?
correct me

Take a look at what the type of the "sc" reference is....

The "sc" reference is a superclass type. Does the equals() method of the superclass type print anything?


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274

roberto nasel posted Today 08:19

Hi all!
I am new to this.

I see, your first posting.
Welcome to the Ranch!!

You have overridden the equals only in the sub class HasHash, but you are invoking the method in the super class:
HasHash ha1 = new HasHash(8);
superclass sc = new superclass(8);

sc doesn't have an overridden equals method. Therefore no printing.


all events occur in real time
Kota li

Joined: Sep 05, 2007
Posts: 20
Originally posted by roberto nasel: you declared int hashCode() return x;
that's it's not printing correct
I agree. Here's the link: http://aspose.com/file-tools
subject: equals() and hascode() doubt
It's not a secret anymore!