Igor Lichs

+ Follow
since Aug 08, 2008
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Igor Lichs

Two answers? I think it's always pre in post.
Yea I called about 5 bookshops and noone has the book.

I suggest you to buy it in www.amazon.com .

A dollar is R$1,6 I think and you can buy it in amazon just paying the post (10 dollars I think). In my opinion, it worth it!

15 years ago
I have them (Study Guide and Mock), but I bought in London and brought them to Brazil.

I'll try to find them here in Curitiba and then I tell you.

Do you need it in Portuguese or can it be in English?
15 years ago

If you run this code, the answer will be false false true
in letter c, it's false true true

hasCode is NOT the memory space where you allocate the object, so x==y is NOT in the very same memory space.

if x is dog1 and y is dog2, they are Dog objects, same properties, but they are NOT in the same memory space.

equals were correctly overriden, so it check the dog1 properties with the dog2 properties and its hashcodes. Does it match? Great! They are equals. If they are equals, their hashCodes MUST be equals, because the question said they were appropriately overriden, and it means the Dog class has overriden the hashCode with the number 123456789 for exemple, so every dog will have the hashCode 123456789.

Can a Cat class have the hashCode 123456789? YES. It's not memory position.

The only possible way to x==y be true, is when you call fun like this:

x = a
y = a

so they are the very same object, so it is TRUE, they are equals, so it is TRUE and their hashCode is the same, so it is TRUE.

true true true is one possible answer, but its NOT in the options. I think I have confused you with my previous post, sorry about that.
Ok, check this out: http://java.sun.com/javase/6/docs/api/java/lang/Object.html#hashCode()

It says: "It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results."

So even if the objects are different, they can have the same hashCode, however, if they are equals, they MUST have the same hashCode, if the equals and the hashCode were appropriately overridden, which it was, according to the question title.

x==y just compares memory spaces. To be true, x and y MUST have to be the SAME object, not just the same type.

Therefore, 2 different object will be false on x==y, false on x.equals(y), but comparing hashCodes they can the same or not. But it's a possibility. So letter a is correct.

If I have 2 Objects CAR and both are MERCEDES, they are not in the same memory space, so x==y is false, but they are equals, so their hashCodes must be the same. So letter c is also correct.

This is the way I see this, at least.
Hey hermano, bad thing what your team did with mine in this Olympics.. 3x0?!?!

ok, serious now, if you aim J2EE, go straight forward to web component developer...
i'm thinking now, why letter b is wrong? why the hashCodes MUST be the same? cant I implement a method which gives me different hashCodes?
I think it has 4 correct answers:

- false false true
- false true true

and other two which are not in the options:

- false false false
- true true true

imagine the following situation in the main method, assuming the fun method is in the TestClass:

that's why i suppose its 4 correct answers and not just 3.

please guys, correct me if i'm wrong, i'm here to learn
but aren't you overriding the equals method?
Is its output really "true" ?

As far as I know, the equals melhod defined in the Object class compares hashCodes.

I just made some implements in your code to print the hashCode:

and the output is:

so their hashCodes are different and this code will never output a "true" message.

are you sure this is all the code?
Hey guys,

This is my first topic

I would like to know what is the utility of bit shift operators.


I know what they are, but I have no idea in what situation should I use them.

Hello mate,

You will be fine, and you ARE ready.

Take the exam!!