aspose file tools*
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
Author

equals() and hascode() doubt

roberto nasel
Greenhorn

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

Thanks
roberto
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18824
    
  40

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?

Henry


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

Joined: Aug 25, 2006
Posts: 1274
Howdy!

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.equals(ha1);

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



Yours,
Bu.


all events occur in real time
Kota li
Greenhorn

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