Question 126

Given:
class FuelNotAvailException extends Exception { }
class Vehicle {
void ride() throws FuelNotAvailException {//line n1
System.out.println("Happy Journey!");
}
}
class SolarVehicle extends Vehicle {
public void ride () throws Exception {//line n2
super ride ();
}
}
and the code fragment:
public static void main (String[] args) throws FuelNotAvailException, Exception {
Vehicle v = new SolarVehicle ();
v.ride();
}
Which modification enables the code fragment to print Happy Journey!?
  • Question 127

    Given:
    class Book {
    int id;
    String name;
    public Book (int id, String name) {
    this.id = id;
    this.name = name;
    }
    public boolean equals (Object obj) { //line n1
    boolean output = false;
    Book b = (Book) obj;
    if (this.name.equals(b name))}
    output = true;
    }
    return output;
    }
    }
    and the code fragment:
    Book b1 = new Book (101, "Java Programing");
    Book b2 = new Book (102, "Java Programing");
    System.out.println (b1.equals(b2)); //line n2
    Which statement is true?
  • Question 128

    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.getString(1));
    16.System.out.println("Description:" + rs.getString(2));
    17.System.out.println("Price:" + rs.getString(3));
    18. System.out.println(Quantity:" + rs.getString(4));
    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 129

    Given the code fragment:
    public static void main (String [ ] args) throws IOException {
    BufferedReader br = new BufferedReader (new InputStremReader (System.in)); System.out.print ("Enter GDP: ");
    //line 1
    }
    Which code fragment, when inserted at line 1, enables the code to read the GDP from the user?
  • Question 130

    Given the code fragment:
    public static void main (String [ ] args) throws IOException {
    BufferedReader br = new BufferedReader (new InputStremReader
    (System.in));
    System.out.print ("Enter GDP: ");
    //line 1
    }
    Which code fragment, when inserted at line 1, enables the code to read the GDP from the user?