Review Questions

graphics/rq_icon.gif

6.12

Which statements are true about interfaces?

Select the two correct answers.

  1. Interfaces allow multiple implementation inheritance.

  2. Interfaces can be extended by any number of other interfaces.

  3. Interfaces can extend any number of other interfaces.

  4. Members of an interface are never static.

  5. Members of an interface can always be declared static.

6.13

Which of these field declarations are legal within the body of an interface?

Select the three correct answers.

  1. public static int answer = 42;

  2. int answer;

  3. final static int answer = 42;

  4. public int answer = 42;

  5. private final static int answer = 42;

6.14

Which statements are true about interfaces?

Select the two correct answers.

  1. The keyword extends is used to specify that an interface inherits from another interface.

  2. The keyword extends is used to specify that a class inherits from an interface.

  3. The keyword implements is used to specify that an interface inherits from another interface.

  4. The keyword implements is used to specify that a class inherits from an interface.

  5. The keyword implements is used to specify that a class inherits from another class.

6.15

Which statement is true about the following code?

// Filename: MyClass.java
abstract class MyClass implements Interface1, Interface2 {
    public void f() { }
    public void g() { }
}

interface Interface1 {
    int VAL_A = 1;
    int VAL_B = 2;

    void f();
    void g();
}

interface Interface2 {
    int VAL_B = 3;
    int VAL_C = 4;

    void g();
    void h();
}

Select the one correct answer.

  1. Interface1 and Interface2 do not match, therefore, MyClass cannot implement them both.

  2. MyClass only implements Interface1. Implementation for void h() from Interface2 is missing.

  3. The declarations of void g() in the two interfaces conflict, therefore, the code will not compile.

  4. The declarations of int VAL_B in the two interfaces conflict, therefore, the code will not compile.

  5. Nothing is wrong with the code, it will compile without errors.

6.16

Given the following code, which declaration can be inserted at the indicated line without causing a compilation error?

interface MyConstants {
    int r = 42;
    int s = 69;
    // INSERT CODE HERE
}

Select the two correct answers.

  1. final double circumference = 2*Math.PI*r;

  2. int total = total + r + s;

  3. int AREA = r*s;

  4. public static MAIN = 15;

  5. protected int CODE = 31337;