Java OCA OCP Practice Question 3239

Question

Given the following interface declaration, which declaration is valid?

interface I {
  void setValue(int val);
  int getValue();
}

Select the one correct answer.

(a) class A extends I {
      int value;//from   ww w  .  j  av  a 2  s. c o  m
      void setValue(int val) { value = val; }
      int getValue() { return value; }
    }
(b) interface B extends I {
      void increment();
    }

 (c) abstract class C implements I {
       int getValue() { return 0; }
       abstract void increment();
      }
 (d)  interface D implements I {
       void increment();
      }
 (e)  class E implements I {
       int value;
       public void setValue(int val) { value = val; }
      }


(b)

Note

Classes cannot extend interfaces, they must implement them.

Interfaces can extend other interfaces, but cannot implement them.

A class must be declared abstract if it does not provide an implementation for one of its methods.

Methods declared in interfaces are implicitly public and abstract.

Classes that implement these methods must explicitly declare their implementations public.




PreviousNext

Related