OCA Java SE 8 Class Design - OCA Mock Question Class Design 8


Choose the correct statement about the following code:

     1: interface Printable { 
     2:   abstract int getNumberOfSections(); 
     3: } 
     4: abstract class Shape implements Printable { 
     5:   abstract int getWidth(); 
     6: } 
     7: public class Rectangle extends Shape { 
     8:   int getWidth() { return 6; } 
     9: } 
  1. It compiles and runs without issue.
  2. The code will not compile because of line 2.
  3. The code will not compile because of line 4.
  4. The code will not compile because of line 7.
  5. It compiles but throws an exception at runtime.




The code fails to compile because Rectangle, the first concrete subclass, doesn't implement getNumberOfSections(), which is inherited as an abstract method; therefore, option D is correct.

B is incorrect since this interface method definition is correct.

C is incorrect since an abstract class is not required to implement any abstract methods, including those inherited from an interface.

E is incorrect because the code fails at compilation-time.