Question 66
Given the code fragment:
9.Connection conn = DriveManager.getConnection(dbURL, userName, passWord);
10.
String query = "SELECT id FROM Employee";
11.
try (Statement stmt = conn.createStatement()) {
12.
ResultSet rs = stmt.executeQuery(query); 13.stmt.executeQuery("SELECT id FROM Customer");
14.
while (rs.next()) {
15.
//process the results 16.System.out.println("Employee ID: "+ rs.getInt("id")); 17.}
18.
} catch (Exception e) {
19.
System.out.println ("Error");
20.
}
Assume that:
The required database driver is configured in the classpath.
The appropriate database is accessible with the dbURL, userName, and passWord exists.
The Employee and Customer tables are available and each table has id column with a few
records and the SQL queries are valid.
What is the result of compiling and executing this code fragment?
Question 67
Given:
interface Doable {
public void doSomething (String s);
}
Which two class definitions compile?
Question 68
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 69
Given the code fragment:
You have been asked to define the ProductCode class. The definition of the ProductCode class must allow c1 instantiation to succeed and cause a compilation error on c2 instantiation.
Which definition of ProductCode meets the requirement?
Question 70
Given the code fragment:
What is the result?
