Question 166

Given the code fragment:

Which should be inserted into line n1to print Average = 2.5?
  • Question 167

    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 168

    Given the code fragments:
    class Caller implements Callable<String> {
    String str;
    public Caller (String s) {this.str=s;}
    public String call()throws Exception { return str.concat ("Caller");}
    }
    class Runner implements Runnable {
    String str;
    public Runner (String s) {this.str=s;}
    public void run () { System.out.println (str.concat ("Runner"));}
    }
    and
    public static void main (String[] args) InterruptedException, ExecutionException { ExecutorService es = Executors.newFixedThreadPool(2); Future f1 = es.submit (new Caller ("Call")); Future f2 = es.submit (new Runner ("Run")); String str1 = (String) f1.get(); String str2 = (String) f2.get();//line n1 System.out.println(str1+ ":" + str2);
    }
    What is the result?
  • Question 169

    Given: What is the result?
  • Question 170

    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!?