• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Confusion in Equals ,== and Hashcodes

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am really confused with ==, Equals and Hashcodes.
Can anyone please explain me the below question?

Q)Your program has two object references, x and y. In some method the following logical tests are done:


boolean hashFlag = ( x.hashCode() == y.hashCode() );
boolean equalsFlag = x.equals( y );
boolean eqFlag = ( x == y );


Which of the following statements about the relationship between these tests are true.

(1)If equalsFlag is true, then hashFlag must be true
(2)If hashFlag is true, then eqFlag must be true
(3)If equalsFlag is false, then eqFlag must be false
(4)if hashFlag is false, then eqFlag must be false

Ans:1,3 and 4.

Thanks,
Jaimesh.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jammy,

pleae take a minute and read this. You are required to post the source of any question you post. post that don't meet this requirement can and will be deleted.

Thanks
 
jammy ponkia
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is from one of the SCJP mock exams provided by Technopark.

Thanks,
Jaimesh.
 
Oh the stink of it! Smell my tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic