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








Question

What is the output of the following code?

     1: public abstract class Shape { 
     2:   public abstract void draw() {}; 
     3:   public static void main(String[] args) { 
     4:     Shape s = new Rectangle(); 
     5:     s.draw(); 
     6:   } 
     7: } 
     8: class Rectangle extends Shape { 
     9:   public void draw(int depth) { System.out.println("Rectangle draw"); } 
     10: } 
  1. Rectangle draw
  2. The code will not compile because of line 2.
  3. The code will not compile because of line 8.
  4. The code will not compile because of line 9.
  5. The output cannot be determined from the code provided.




Answer



B.

Note

Line 2 contains an invalid definition of an abstract method.

Abstract methods cannot contain a body, so the code will not compile and B is the correct answer.