Java OCA OCP Practice Question 2051

Question

Suppose the ResultSet is scrollable and contains 10 rows with the values 1-10 respectively.

What is the output of the following?.

5:  rs.absolute(0); 
6:  rs.relative(5); 
7:  rs.relative(-10); 
8:  rs.relative(5); 
9:  System.out.print(rs.getInt(1)); 
  • A. 4
  • B. 5
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


B.

Note

The cursor starts out at position zero, right before the first row.

Line 6 moves the cursor to position five.

Line 7 tries to move the cursor ten rows before that position which is row negative five.

Since you can't move back before row zero, the cursor is at row zero instead.

Then line 8 moves the cursor forward five positions from row zero, leaving it at row five and making Option B the answer.




PreviousNext

Related