For the questions below, consider a class called ChessPiece. This class has two instance data, String type and int player. The variable type will store "King", "Queen", "Bishop", etc and the int player will store 0 or 1 depending on whose piece it is. We wish to implement Comparable for the ChessPiece class. Assume that, the current ChessPiece is compared to a ChessPiece passed as a parameter. Pieces are ordered as follows: "Pawn" is a lesser piece to a "Knight" and a "Bishop", "Knight" and "Bishop" are equivalent for this example, both are lesser pieces to a "Rook" which is a lesser piece to a "Queen" which is a lesser piece to a "King."
-Which of the following method headers would properly define the method needed to make this class Comparable?
A) public boolean comparable(Object cp)
B) public int comparable(Object cp)
C) public int compareTo(Object cp)
D) public int compareTo( )
E) public boolean compareTo(Object cp)
Correct Answer:
Verified
Q10: It is important to dissect a problem
Q15: All objects implement Comparable.
Q23: Which of the following would not be
Q31: Which Layout Manager type would you use
Q32: In order to implement Comparable in a
Q32: In which phase of program development would
Q37: Which Layout Manager is used by default
Q38: Which of the following GUI classes requires
Q39: In order to display three components vertically
Q40: For the questions below, consider a class
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents