1z0-809 Java SE 8 Programmer II

Loading demo links...

Showing 10–12 of 15 questions

Question 10

Given the code fragment:

You have been asked to define the ProductCode class. The definition of the ProductCode class must allow c1 instantiation to succeed and cause a compilation error on c2 instantiation.

Which definition of ProductCode meets the requirement?

Select an option, then click Submit answer.

  • Option A

  • Option B

  • Option C

  • Option D

Question 11

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 FuelNotAvailException { //line n2 super ride ();

}

}

and the code fragment:

public static void main (String[] args) throws Exception { Vehicle v = new SolarVehicle ();

v.ride(); }

Which modification enables the code fragment to print Happy Journey!?

Select an option, then click Submit answer.

  • Replace line n1 with public void ride() throws FuelNotAvailException {

  • Replace line n1 with protected void ride() throws Exception {

  • Replace line n2 with public void ride()throws FuelNotAvailException, Exception {

  • Replace line n2 with private void ride() throws FuelNotAvailException {

Question 12

Given the code fragment:

Assume that dbURL, userName, and password are valid.

Which code fragment can be inserted at line n1 to enable the code to print Connection Established?

Select an option, then click Submit answer.

  • Properties prop = new Properties(); prop.put (“user”, userName); prop.put (“password”, password); con = DriverManager.getConnection (dbURL, prop);

  • con = DriverManager.getConnection (userName, password, dbURL);

  • Properties prop = new Properties(); prop.put (“userid”, userName); prop.put (“password”, password); prop.put(“url”, dbURL); con = DriverManager.getConnection (prop);

  • con = DriverManager.getConnection (dbURL); con.setClientInfo (“user”, userName); con.setClientInfo (“password”, password);