Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method signatures question

 
Daniel Lucas
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK here's the question:

Consider the following class declaration.

public class SomeClass implements Comparable
{
// ... other methods not shown
}

Which of the following method signatures of compareTo will satisfy the Comparable interface requirement?

I. public int compareTo (Object other)
II. public int compareTo (SomeClass other)
III. public boolean compareTo (Object other)

(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I, II, and III

My analysis:

OK so I'm given a class named SomeClass that implements Comparable (I've used implements ActionListener before, but never Comparable... I'll assume it compares two things)

So it needs a method signature that satisfies the Comparable interface requirement. First of all, I can't recall ever hearing about "method signatures" used as a term in my Java course. But I do remember seeing something that looks like methodName(Object other). From what I can see, the answer choices all involve two of three things: an Object, SomeClass (the class from above), and other. Answer choices I and II declare the method named compareTo an integer, while answer choice III declares the method compareTo as a boolean. I know boolean deals with true or false statements, and an integer is 0, 1, 2, 3, 4, etc. Now I need to satisfy the interface requirement, whatever the heck that is. So if I were doing this question on the AP Comp Sci A exam and being timed, I think at this point I would guess and put A, I only. Why? Because it looks right. I don't really have reasoning besides that. Am I right? *checks answer key* Yep! The answer is A. I guess this is just testing my knowledge of what a method signature looks like. Apparently I recalled correctly...
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know boolean deals with true or false statements, and an integer is 0, 1, 2, 3, 4, etc. Now I need to satisfy the interface requirement, whatever the heck that is. So if I were doing this question on the AP Comp Sci A exam and being timed, I think at this point I would guess and put A, I only. Why? Because it looks right. I don't really have reasoning besides that. Am I right? *checks answer key* Yep! The answer is A. I guess this is just testing my knowledge of what a method signature looks like. Apparently I recalled correctly...


Unfortunately, you just happened to pick the right answer by pure luck. This is a test question on how well you know the Comparable interface -- not on whether you know what a method is...

To answer the question, take a look at the java.lang.Comparable interface -- either using the source code or the Java Doc.



Choice A is correct because it matches the interface definition. Not because it looks closest like a method signature.

Henry
 
Daniel Lucas
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, now I know about the Comparable interface...

How would I go about finding the answer using the source code or the Java Doc? What is the Java Doc? EDIT: nevermind, it's on the Sun website.
[ April 30, 2006: Message edited by: Daniel Lucas ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic