exam questions

Exam 1z0-809 All Questions

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

Exam 1z0-809 topic 1 question 187 discussion

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

Given:
class Vehicle implements Comparable<Vehicle>{
int vno;
String name;
public Vehicle (int vno, String name) {
this.vno = vno,;
this.name = name;
}
public String toString () {
return vno + ":" + name;
}
public int compareTo(Vehicle o) {
return this.name.compareTo(o.name);
}
and this code fragment:
Set<Vehicle> vehicles = new TreeSet <> ();
vehicles.add(new Vehicle (10123, "Ford"));
vehicles.add(new Vehicle (10124, "BMW"));
System.out.println(vehicles);
What is the result?

  • A. [10123:Ford, 10124:BMW]
  • B. [10124:BMW, 10123:Ford]
  • C. A compilation error occurs.
  • D. A ClassCastException is thrown at run time.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

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
jduarte
Highly Voted 3 years, 5 months ago
Answer is B. Tested
upvoted 5 times
...
asdfjhfgjuaDCV
Most Recent 4 months, 1 week ago
b is the correct answer
upvoted 1 times
...
steefaand
5 months, 1 week ago
Selected Answer: B
B is correct, tested. List is sorted by name, not id.
upvoted 1 times
...
duydn
10 months ago
Selected Answer: B
Answer is B. Sort is ASC
upvoted 1 times
...
_Ismail_
2 years, 1 month ago
B- tested
upvoted 2 times
...
samtash1034
2 years, 6 months ago
Answer is D,tested
upvoted 1 times
...
Svetleto13
3 years, 2 months ago
B,tested.If we check the code with return o.name.compareTo(this.name); answer is A.
upvoted 1 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