Java OCA OCP Practice Question 2881

Question

Given:

2. interface Printable { }  
3. interface Writable { }  
4. abstract interface Shape extends Printable, Writable {  
5.   void pullShape();  
6. }  //from w  w w. java  2s . c  om
7. class Rectangle implements Shape {  
8.   public void pullShape() { System.out.print("pulling "); }  
9. }  
10. class Square implements Shape extends Rectangle  {  
11.   public void pullShape() { System.out.print("pulling harder "); }  
12. }  
13. public class Box extends Rectangle implements Shape, Writable { } 

What is the result? (Choose all that apply.)

  • A. Compilation succeeds.
  • B. Compilation fails because of error(s) in Shape.
  • C. Compilation fails because of error(s) in Rectangle.
  • D. Compilation fails because of error(s) in Square.
  • E. Compilation fails because of error(s) in Box.


D is correct.

Note

When a class implements and extends, the extends declaration comes first.

A, B, C, and E are incorrect because all of the other code is legal.

It is legal to "re-extend" an interface, and it's legal to implement several interfaces.




PreviousNext

Related