Question 141

Given the code fragment:

Which code fragment, when inserted at line 3, enables the code to print 10:20?
  • Question 142

    Given:
    public class Test<T> {
    private T t;
    public T get () {
    return t;
    }
    public void set (T t) {
    this.t = t;
    }
    public static void main (String args [ ] ) {
    Test<String> type = new Test<>();
    Test type 1 = new Test (); //line n1
    type.set("Java");
    type1.set(100); //line n2
    System.out.print(type.get() + " " + type1.get());
    }
    }
    What is the result?
    Java 100
  • Question 143

    Given:
    Item table
    ID, INTEGER: PK
    DESCRIP, VARCHAR(100)
    PRICE, REAL
    QUANTITY< INTEGER
    And given the code fragment:
    9. try {
    10.Connection conn = DriveManager.getConnection(dbURL, username,
    password);
    11. String query = "Select * FROM Item WHERE ID = 110";
    12. Statement stmt = conn.createStatement();
    13. ResultSet rs = stmt.executeQuery(query);
    14.while(rs.next()) {
    15.System.out.println("ID:" + rs.getInt("Id"));
    16.System.out.println("Description:" + rs.getString("Descrip"));
    17.System.out.println("Price:" + rs.getDouble("Price"));
    18. System.out.println(Quantity:" + rs.getInt("Quantity"));
    19.}
    20. } catch (SQLException se) {
    21. System.out.println("Error");
    22. }
    Assume that:
    - The required database driver is configured in the classpath.
    - The appropriate database is accessible with the dbURL, userName, and
    passWord exists.
    - The SQL query is valid.
    What is the result?
  • Question 144

    Given the code fragment:
    List<String> empDetails = Arrays.asList("100, Robin, HR",
    " 200, Mary, AdminServices",
    " 101, Peter, HR");
    empDetails.stream()
    .filter(s-> s.contains("1"))
    .sorted()
    .forEach(System.out::println); //line n1
    What is the result?
  • Question 145

    Given the code fragment:
    List<Integer> codes = Arrays.asList (10, 20);
    UnaryOperator<Double> uo = s -> s +10.0;
    codes.replaceAll(uo);
    codes.forEach(c -> System.out.println(c));
    What is the result?