Question 16

Given the code fragments:
public class Book implements Comparator<Book> {
String name;
double price;
public Book () {}
public Book(String name, double price) {
this.name = name;
this.price = price;
}
public int compare(Book b1, Book b2) {
return b1.name.compareTo(b2.name);
}
public String toString() {
return name + ":" + price;
}
}
and
List<Book>books = Arrays.asList (new Book ("Beginning with Java", 2), new book ("A
Guide to Java Tour", 3));
Collections.sort(books, new Book());
System.out.print(books);
What is the result?
  • Question 17

    Which two are elements of a singleton class? (Choose two.)
  • Question 18

    Which two methods from the java.util.stream.Streaminterface perform a reduction operation?
    (Choose two.)
  • Question 19

    Given:

    What is the result?
  • Question 20

    Given the code fragment:

    Assume that:
    The required database driver is configured in the classpath.
    The appropriate database is accessible with the dbURL, userName, and passWordexists The Employeetable has a column ID of type integer and the SQL query matches one record.
    What is the result?