Question 26

Given the code fragment:
Path file = Paths.get ("courses.txt");
// line n1
Assume the courses.txt is accessible.
Which code fragment can be inserted at line n1 to enable the code to print the content of the courses.txt file?
  • Question 27

    Given:

    and the code fragment:

    What is the result?
    true
  • Question 28

    Given:
    public final class IceCream {
    public void prepare() {}
    }
    public class Cake {
    public final void bake(int min, int temp) {}
    public void mix() {}
    }
    public class Shop {
    private Cake c = new Cake ();
    private final double discount = 0.25;
    public void makeReady () { c.bake(10, 120); }
    }
    public class Bread extends Cake {
    public void bake(int minutes, int temperature) {}
    public void addToppings() {}
    }
    Which statement is true?
  • Question 29

    Given the code fragment:
    public class Foo {
    public static void main (String [ ] args) {
    Map<Integer, String> unsortMap = new HashMap<> ( );
    unsortMap.put (10, "z");
    unsortMap.put (5, "b");
    unsortMap.put (1, "d");
    unsortMap.put (7, "e");
    unsortMap.put (50, "j");
    Map<Integer, String> treeMap = new TreeMap <Integer, String> (new
    Comparator<Integer> ( ) {
    @ Override public int compare (Integer o1, Integer o2) {return o2.compareTo (o1); } } ); treeMap.putAll (unsortMap); for (Map.Entry<Integer, String> entry : treeMap.entrySet () ) { System.out.print (entry.getValue () + " ");
    }
    }
    }
    What is the result?
  • Question 30

    Given that course.txt is accessible and contains:
    Course : : Java
    and given the code fragment:
    public static void main (String[ ] args) {
    int i;
    char c;
    try (FileInputStream fis = new FileInputStream ("course.txt");
    InputStreamReader isr = new InputStreamReader(fis);) {
    while (isr.ready()) { //line n1
    isr.skip(2);
    i = isr.read ();
    c = (char) i;
    System.out.print(c);
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    What is the result?
    ur :: va