Java OCA OCP Practice Question 1006

Question

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

public interface Printable {} 
public class Shape implements Printable { 
   public static void main(String[] args) { 
          frog = new Square(); 
   } 
} 

public class Rectangle extends Shape {} 
public class Square extends Shape {} 
  • A. Shape
  • B. Square
  • C. Rectangle
  • D. Printable
  • E. Object
  • F. Long


A, B, D, E.

Note

The blank can be filled with any class or interface that is a super type of Square.

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

Rectangle is not a superclass of Square, so option C is incorrect.

Square inherits the Printable interface, so option D is correct.

All classes inherit Object, so option E is correct.

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




PreviousNext

Related