Java OCA OCP Practice Question 1027

Question

Which statements are true about the following code?

Choose all that apply

1: interface Printable { 
2:   public abstract void print(); 
3: } 
4: public interface Writable extends Printable { 
5:   public void write(); 
6: } 
  • A. The Writable interface doesn't compile.
  • B. A class that implements Printable must override the print() method.
  • C. A class that implements Writable inherits both the print() and write() methods.
  • D. A class that implements Writable only inherits the write() method.
  • E. An interface cannot extend another interface.


C.

Note

The code compiles without issue, so option A is wrong.

Option B is incorrect, since an abstract class could implement Printable without the need to override the print() method.

Option C is correct; any class that implements Writable automatically inherits its methods, as well as any inherited methods defined in the parent interface. Because option C is correct, it follows that option D is incorrect.

Finally, an interface can extend multiple interfaces, so option E is incorrect.




PreviousNext

Related