Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Mock exam 2 Question 31 on OCP Oracle Certified Professional Java SE8 Programmer II Study Guide

 
Ranch Hand
Posts: 45
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

This question is regarding an explanation of answer on a question in one of the mock exam questions in the book: OCP Oracle Certified Professional Java SE8 Programmer II Study Guide by Jeanne Boyarsky and Scott Selikoff.

tb067900.JaSE8PrgIISG.be2.31. Which of the following can fill in the blank correctly?


A. int num = rs.getInt(0);
B. int num = rs.getInt(1);
C. int num = rs.getInteger(0);
D. int num = rs.getInteger(1);
E. int num = rs.getObject(0);
F. int num = rs.getObject(1);

The answer is as follows:
In a ResultSet, columns are indexed starting with 1, not 0. Therefore, choices A, C, and E are incorrect. There are methods to get the column as an int or Object. However, choice F is incorrect because an Object cannot be assigned to a String without a cast. Choice D is incorrect because the method is not named getInteger().

I think the explanation should say “an Object cannot be assigned to an int” rather than “an Object cannot be assigned to a String”.

In addition to I have a question on the phrase “There are methods to get the column as an int or Object.” At first I thought would be there only 2 methods getInt() and getObject() but there are a lot of methods for example getString().
Is correct the expression? I'm not english mother-tongue therefore I not sure the phrase expresses there are other methods more than int and object.
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just added this to the errata and credited you. I also checked the Java 11 and 17 mocks and it is correct in those.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic