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








Question

Which of the following statements can be inserted in the ___ line so that the code will compile successfully? (Choose all that apply)

     public interface Printable {} 
     public class Rectangle implements Printable { 
        public static void main(String[] args) { 
           ____  frog = new RoundRectangle(); 
        } 
     } 
    
     public class RedRoundRectangle extends Rectangle {} 
     public class RoundRectangle extends Rectangle {} 
  1. Rectangle
  2. RoundRectangle
  3. RedRoundRectangle
  4. Printable
  5. Object
  6. Long




Answer



A, B, D, E.

Note

The ___ can be filled with any class or interface that is a supertype of RoundRectangle.

A is a superclass of RoundRectangle, and B is the same class, so both are correct.

RedRoundRectangle is not a superclass of RoundRectangle, so C is incorrect.

RoundRectangle inherits the Printable interface, so D is correct.

All classes inherit Object, so E is correct.

Long is an unrelated class that is not a superclass of RoundRectangle, and is therefore incorrect.