• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Question regarding javacertificate.com study question

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some concerns regarding a question I saw at javacertificate.com. Here's the question.

I believe the answer is (4), since the class Computer is supposed to implement the Comparable interface, but neither implements " int compare(Object, Object) " nor is declared abstract. But according to javacertificate.com, the answer is (2). What am I missing, or is javacertificate.com wrong? Thanks.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Comaparable interface has one method:
public int compareTo(Object o)
This is indeed implemented. I do not believe, however, that it is ever invoked as it seems to be used by sort methods of the Collections and Array classes.
Three objects are added to the HashSet on the basis of them not being the same (not having the same object references) according to the equals method inherited from Object.
 
David Willis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I see what I did. I got the Comparable and Comparator interfaces mixed up.
Thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic