Forums Register Login

question on equals & instanceof

+Pie Number of slices to send: Send
What is the result of compiling the following class?


Answers
A. The class compiles successfully.
B. Line 6 causes a compiler error because hashCode does not return a unique value.
C. Line 10 causes a compiler error because the equals method does not override the parent
method correctly.
D. Line 14 does not compile because the ClassCastException is not handled or declared.
E. Line 15 does not compile because other.ISBN is a private field.


Question 1
Why A is the answer?

Question 2
What is this.ISBN refers to?
+Pie Number of slices to send: Send
 

thejaka samarakoon wrote:

Question 1
Why A is the answer?

Question 2
What is this.ISBN refers to?



There is no problem, so why do you think, there might be a error? this mean, the object, on which you've invoked the equals() method.
+Pie Number of slices to send: Send
 

thejaka samarakoon wrote:
Question 1
Why A is the answer?


what makes you to think that this program wont compile?

thejaka samarakoon wrote:
Question 2
What is this.ISBN refers to?



it holds int values.[default 0]
+Pie Number of slices to send: Send
As a side note : all the instances of this class would be same always[in case of equals check]
+Pie Number of slices to send: Send
 

Seetharaman Venkatasamy wrote:As a side note : all the instances of this class would be same always[in case of equals check]



Is it in this example, this.ISBN is referring to Book object ?That is the thing i have to be clear with.
+Pie Number of slices to send: Send
this.ISBN is same as ISBM . i.e, currently executing object.

related to my previous post, how do you set value to ISBN?
+Pie Number of slices to send: Send
 

thejaka samarakoon wrote:
Is it in this example, this.ISBN is referring to Book object ?That is the thing i have to be clear with.



this means, the currently executing object, and this.ISBN means the variable of the currently executing object!
+Pie Number of slices to send: Send
Thanks Abimaran Kugathasan & Seetharaman Venkatasamy
+Pie Number of slices to send: Send
 

thejaka samarakoon wrote:Thanks Abimaran Kugathasan & Seetharaman Venkatasamy



You are welcome
+Pie Number of slices to send: Send
 

thejaka samarakoon wrote:Thanks Abimaran Kugathasan & Seetharaman Venkatasamy


You are Welcome
I was her plaything! And so was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 792 times.
Similar Threads
validating equals method
relation is required B/W class and type before <useBean>
hashcode question
JWebPlus exam question
hashCode(), equals(): Got question right, but for the wrong reasons
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:38:46.