This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes book example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "book example" Watch "book example" New topic

book example

dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
chapter:7, example 7,page no;626
Can anybody help me to solve this example? I am not getting it,
Thanks in advance.

SCJP-1.5<br />SCWCD-1.4
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
I want to add that , I am not getting second method. Why we dont need instanceof test for boolean equals().
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 10929


You don't mention WHAT book. Even at that, not everyone HAS whatever book you are talking about. Can you post the actual code/question?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Padma Asrani
Ranch Hand

Joined: Mar 22, 2007
Posts: 111

I guess you are talking about K&B test.

The instanceof test is required for equals method to know that you are comparing the objects which are comparable.

This statement might be vague, so I will give an example.
For example If I have a code like this.

This returns Not Equal because the String and StringBuffer are not comparable. Both classes derived from Object but there is not relation between String class Objects and StringBuffer class Objects, so the instanceof test inside equals method in String class will fail and as a result it will return false.

I hope this is clear.

dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Fred I am talking about K & B book.

Padma I got your point. Thanks for that.
But here in boolean equals() we have to do instanceof test for ToDos. So my question was that?
It is sorta covered in the JavaRanch Style Guide.
subject: book example
Similar Threads
count yourself in javaranch#~
when 400 mark will reach?
problem with tag files
lucky number
Your lucky number