• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

equals() and hascode() doubt

 
roberto nasel
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20889
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kota li
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by roberto nasel: you declared int hashCode() return x;
that's it's not printing correct
[QB][/QB]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic