Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Oracle Exam 1Z0-809 Topic 2 Question 8 Discussion

Actual exam question for Oracle's 1Z0-809 exam
Question #: 8
Topic #: 2
[All 1Z0-809 Questions]

Given:

class Vehicle {

int vno;

String name;

public Vehicle (int vno, String name) {

this.vno = vno,;

this.name = name;

}

public String toString () {

return vno + '':'' + name;

}

}

and this code fragment:

Set vehicles = new TreeSet <> ();

vehicles.add(new Vehicle (10123, ''Ford''));

vehicles.add(new Vehicle (10124, ''BMW''));

System.out.println(vehicles);

What is the result?

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

Annmarie
28 days ago
Ah, the good old 'Vehicle doesn't know how to drive itself' problem. Guess we'll have to call an Uber to get these cars in order.
upvoted 0 times
...
Daniela
29 days ago
Ah, the old 'forget to implement Comparable' trick. Classic! I'm feeling lucky, so I'm going with D, a good old ClassCastException is the way to go.
upvoted 0 times
...
Arlene
30 days ago
Hold up, is this a trick question? If the class doesn't implement Comparable, how is the TreeSet going to know how to sort the vehicles? I'm going with C, gotta be a compilation error.
upvoted 0 times
...
Lea
1 months ago
Hah, looks like someone forgot the Comparable interface. I'm betting on D, a ClassCastException is the only logical outcome here.
upvoted 0 times
Frank
2 days ago
I think you're right, without implementing the Comparable interface, a ClassCastException will be thrown.
upvoted 0 times
...
...
Blondell
2 months ago
Wait, the class doesn't implement Comparable? How are we supposed to sort the vehicles then? I'll go with C, a compilation error is bound to happen.
upvoted 0 times
Denna
1 months ago
User2
upvoted 0 times
...
Brandon
2 months ago
User1
upvoted 0 times
...
...
Van
2 months ago
I'm not sure, but I think the TreeSet will use the natural ordering of the Vehicle objects based on the compareTo method.
upvoted 0 times
...
Antonio
2 months ago
I agree with Genevieve, the code fragment adds vehicles to a TreeSet which will sort them in natural order.
upvoted 0 times
...
Genevieve
2 months ago
I think the answer is A) 10123 Ford10124 BMW.
upvoted 0 times
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77