Oracle
1Z0-809 · Question #238
1Z0-809 Question #238: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-809 to reveal the answer and full explanation for question #238. The question stem and answer options stay visible for context.
Question
Given:
class Block {
String color;
int size;
Block(int size, String color) {
this.size = size;
this.color = color;
}
}
and the code fragment:
List<Block> blocks = new ArrayList<>();
blocks.add(new Block(10, "Green"));
blocks.add(new Block(7, "Red"));
blocks.add(new Block(12, "Blue"));
Collections.sort(blocks, new ColorSorter());
Which definition of the ColorSorter class sorts the blocks list?
Options
- Aclass ColorSorter implements Comparable<Block> { public boolean compare(Block o1, Block o2) { return o1.color.equals(o2.color); } }
- Bclass ColorSorter implements Comparator<Block> { public int compareTo(Block o1, Block o2) { return o1.color.compareTo(o2.color); } }
- Cclass ColorSorter implements Comparator<Block> { public int compare(Block o1, Block o2) { return o1.color.compareTo(o2.color); } }
- Dclass ColorSorter implements Comparator<Block> { public boolean compare(Block o1, Block o2) { return o1.color.equals(o2.color); } }
Unlock 1Z0-809 to see the answer
You've previewed enough free 1Z0-809 questions. Unlock 1Z0-809 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.