Code Description Ch 07-1
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"
a "Bishop" and "Knight" are equivalent for this example
both "Bishop" and "Knight" are lesser pieces to a "Rook"
a "Rook" is a lesser piece to a "Queen"
a "Queen" is a lesser piece to a "King".
-Refer to Code Description Ch 07-1: Which of the following method headers would properly define the method needed to make this class Comparable? (cp designates ChessPiece)
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
Q20: The activities of the development cycle are
Q21: Having multiple class methods of the same
Q21: Abstract methods are used when defining
A) interface
Q23: Which of the following would not be
Q24: Define an interface class that contains two
Q26: Which of the following methods is a
Q27: In order to create a constant, you
Q28: Static methods cannot
A) reference instance data
B) reference
Q29: In which phase of program development would
Q49: Explain the difference between implementing an interface
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