Question

Consider the following Java code snippet:     import java.util.PriorityQueue;     class CustomObject {         int id;         String name;         public CustomObject(int id, String name) {             this.id = id;             this.name = name;         }     }     public class HeapQuestion6 {         public static void main(String[] args) {             PriorityQueue pq = new PriorityQueue();             pq.add(new CustomObject(1, "Alice"));             pq.add(new CustomObject(2, "Bob"));             System.out.println(pq.poll().name);         }     }     What will be the result of compiling and running this program?

A It will compile and print "Alice".
B It will compile and print "Bob".
C It will compile but throw a ClassCastException at runtime.
D It will result in a compilation error because CustomObject does not implement Comparable.
E It will compile and print the object's hash code.
Practice Next

Hey! Ask a query