Question 127 of 130 from exam 1Z0-809: Java SE 8 Programmer II

Question 127 of 130 from exam 1Z0-809: Java SE 8 Programmer II

Question

Given:

class Block {
String color;

int size;
Block(int size, string color)
this.size = size;
this.color = colo:
List<Block> blocks = new ArrayList<>()i
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? A.

class ColorSorter implements Comparable<Block> {
public boolean compare (Block 01, Block 02) {
return ol.color.equals(o2.color) ;

B.

class ColorSorter implements Comparable<Block> {
public int compareTo(Block oi, Block 02) {
return o1.color.compareTo (02.color) ;
}

C.

class ColorSorter implements Comparator<Block> {
public int compare (Block 01, Block 02) {
return o1.color.compareTo (02.color) ;
i

D.

class ColorSorter implements Comparator<Block> {
public boolean compare (Block 01, Block 02) {
return o1.color.compareTo(o2.color)

Explanations

C.