Java OCA OCP Practice Question 2906

Question

Suppose that you have a table named animal with two rows. What is the result of the following code?

6:    Connection conn = new Connection(url, userName, password); 
7:    Statement stmt = conn.createStatement(); 
8:    ResultSet rs = stmt.executeQuery("select count(*) from animal"); 
9:    if (rs.next()) System.out.println(rs.getInt(1)); 
  • A. 0
  • B. 2
  • C. There is a compiler error on line 6.
  • D. There is a compiler error on line 9.
  • E. There is a compiler error on another line.
  • F. A runtime exception is thrown.


C.

Note

A Connection is created using a static method on DriverManager.

It does not use a constructor.

Therefore, choice C is correct.

If the Connection was created properly, the answer would be choice B.




PreviousNext

Related