exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 142 discussion

Actual exam question from Oracle's 1z0-809
Question #: 142
Topic #: 1
[All 1z0-809 Questions]

Given:
and the code fragment:

Which definition of the ColorSorter class sorts the blocks list?
A.

B.

C.

D.

Show Suggested Answer Hide Answer
Suggested Answer: C

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Tarik2190
Highly Voted 3 years, 2 months ago
Answer is C, import java.util.*; class Block { String color; int size; public Block(int size, String color) { this.color = color; this.size = size; } @Override public String toString() { return "Block{" + "color='" + color + '\'' + ", size=" + size + '}'; } } class ColorSorter<B> implements Comparator<Block> { public int compare(Block o1, Block o2) { return o1.color.compareTo(o2.color); } } public class Test { public static void main (String[] args) throws InterruptedException { 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()); System.out.println(blocks); } }
upvoted 5 times
...
steefaand
Most Recent 5 months, 4 weeks ago
C is true. With Comparator you must override public int compare(Block b1, Block b2) method.
upvoted 1 times
...
harshgupta1990
3 years, 3 months ago
c is correct. Tested
upvoted 4 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago