Java OCA OCP Practice Question 2994

Question

Given:

2. interface Printable {  void print();  }  
3. // insert code here 

Which code, inserted independently at line 3, will compile? (Choose all that apply.)

  • A. interface Main extends Printable { }
  • B. interface Main extends Printable { void print(); }
  • C. interface Main extends Printable { void doPrint(); }
  • D. interface Main extends Printable { void print() { ; } }
  • E. interface Main extends Printable { protected void print(); }
  • F. interface Main extends Printable { void print(); void doPrint(); }


A, B, C, and F are correct.

Note

When an interface extends another interface, it doesn't have to actually implement anything-in fact, it CANNOT implement anything.

D is incorrect because the extending interface is trying to implement a method.

E is incorrect because interface methods can be only public.




PreviousNext

Related