aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B Bonus Exam, Comparable doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B Bonus Exam, Comparable doubt" Watch "K&B Bonus Exam, Comparable doubt" New topic
Author

K&B Bonus Exam, Comparable doubt

Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi,


You can use java.lang.Comaprable and java.util.Comparator to
sort collections whole elements are of any valid java type,
as long as all of the collection's elements are of the same class.


This is declared as wrong option.
The reason is given below:

It is incorrect because if a class is final and does not alreadt
implements Comparable, then Comparable can't be used to sort that
class.

I don't understand what is that talking about.

Please guide.

Thanks,


cmbhatt
megha joshi
Ranch Hand

Joined: Feb 20, 2007
Posts: 206
Hi Chandra,

Its becuase..to sort elements of a class using Comparable, the implementation of the class has to be modified to include CompareTo() method.

So if the class doesnt implement Comparable and its final....than we can't add CompareTo() to it right...

So it can only be sorted using Comparator...as Comparator can be implemented by a external class rather than the class itself.

As the statement uses the word "and" its false...if it would have used "or" it will be true.

(I know I gave such an answer before about a statement using word "creates" ..so )I might not be right here tooo....
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Thanks Megha,

I got that!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B Bonus Exam, Comparable doubt