aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question on equals & instanceof Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question on equals & instanceof" Watch "question on equals & instanceof" New topic
Author

question on equals & instanceof

thejaka samarakoon
Ranch Hand

Joined: Jul 20, 2010
Posts: 56
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?
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

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.


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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]
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

As a side note : all the instances of this class would be same always[in case of equals check]
thejaka samarakoon
Ranch Hand

Joined: Jul 20, 2010
Posts: 56
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.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

this.ISBN is same as ISBM . i.e, currently executing object.

related to my previous post, how do you set value to ISBN?
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

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!
thejaka samarakoon
Ranch Hand

Joined: Jul 20, 2010
Posts: 56
Thanks Abimaran Kugathasan & Seetharaman Venkatasamy
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

thejaka samarakoon wrote:Thanks Abimaran Kugathasan & Seetharaman Venkatasamy


You are welcome
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

thejaka samarakoon wrote:Thanks Abimaran Kugathasan & Seetharaman Venkatasamy

You are Welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question on equals & instanceof