OCA Java SE 8 Mock Exam - OCA Mock Question 26








Question

Select the correct combinations of assignments of a variable:

interface Printable {} 
class Shape {} 
class Rectangle extends Shape implements Printable {} 
  1. Printable var1 = new Printable();
  2. Shape var2 = new Shape();
  3. Rectangle var3 = new Shape();
  4. Printable var4 = new Shape();
  5. Printable var5 = new Rectangle();




Answer



b, e

Note

A is incorrect. An interface can't be instantiated.

C is incorrect. A reference variable of a derived class can't be used to refer to an object of its base class.

D is incorrect. A reference variable of type Printable can't be used to refer to an object of the class Shape because Shape doesn't implement the interface Printable.