• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Equals and Hashcode

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class hashtest1 {
public static void main(String[] args) {
Foo f1= new Foo();
Foo f2=f1;
Foo f3= new Foo();
}
}

Assuming that Foo has correctly implemented hashCode and equals methods, which of the following will always print out "true" ?

Options:

if(f1.equals(f2)) System.out.println("true");
if(f1.hashCode() == f2.hashCode()) System.out.println("true");
if(f1.hashCode() != f3.hashCode()) System.out.println("true");
if(f1 == f2) System.out.println("true");

Can someone explain me the answer for this question?

Thanks,
Jaimesh
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jammy ponkia,

It is important that you always QuoteYourSources when posting mock questions to Javaranch.

Questions without sources are subject to being deleted.
reply
    Bookmark Topic Watch Topic
  • New Topic