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








Question

What is the output of the following code?

     1: class Shape { 
     2:   public Shape(int edge) { 
     3:     System.out.print("Shape"); 
     4:   } 
     5: } 
     6: public class Rectangle extends Shape { 
     7:   public Rectangle() { 
     8:     System.out.print("Rectangle"); 
     9:   } 
     10:   public static void main(String[] args) { 
     11:     new Shape(5); 
     12:   } 
     13: } 
  1. Rectangle
  2. Shape
  3. RectangleShape
  4. ShapeRectangle
  5. The code will not compile because of line 8.
  6. The code will not compile because of line 11.




Answer



E.

Note

The code will not compile because the parent class Shape doesn't define a no-argument constructor, so the first line of a Rectangle constructor should be an explicit call to super(int edge).