Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Ron McLeod
Junilu Lacar
Liutauras Vilda
Sheriffs:
Paul Clapham
Jeanne Boyarsky
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Piet Souris
Carey Brown
Bartenders:
Jesse Duncan
Frits Walraven
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
master exam doubt
V Gala
Ranch Hand
Posts: 113
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
int x=0;
if(x1.hashcode()!=x2.hashcode())x=x+1;
if(x3.equals(x4)==false)x=x+10;
if(x5.equals(x6)==true)x=x+100;
if(x7.hashcode()==x8.hashcode())x=x+1000;
If o/p is 1111
which is always true
x5.hashcode()==x6.hashcode()
x3.hashcode()!=x4.hashcode()
x1.equals(x2)==true
x7.equals(x8)==true
I thinks answer should be x5.hashcode()==x6.hashcode()
but the answer was given x1.equals(x2)==true
Is answer given wrong?
SureshKumar Sadagopal
Greenhorn
Posts: 1
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Could you please publish the full code, what the values of x1,x2 ... so on..
Regards
Suresh S
John Stone
Ranch Hand
Posts: 332
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I think you are right.
If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
if x1.equals(x2)==true
then they should give same hashcode, but then the output can not be 1111 (you would miss 1 at the end)
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
urgent help on K&B chapter 7 Self Test Questions
Can't Understand... K&B Mock Exam
HashCode and Equals Contract Question from Master Exam Learner Key
Question from Mock exam
Master Exma question
More...