Java OCA OCP Practice Question 1576

Question

Given the following code, which statements are true?

interface Printable  { String describe ();  }

class Shape implements Printable{
   String name;//from  w w  w  .  j a v  a  2s .  com
   public String describe (){ return " 4 Wheeler " + name;  }
}

class Rectangle extends Shape{
    String name;
    public String describe (){ return " 2 Wheeler " + name;  }
}

Select 3 options

  • A. An instance of Rectangle is also an instance of Shape.
  • B. An instance of Rectangle is a valid instance of Printable.
  • C. The use of inheritance is not justified here because a Rectangle is not really a Shape.
  • D. The code will compile only if name is removed from Rectangle.
  • E. The code will fail to compile.


Correct Options are  : A B C

Note

The use of inheritance in this code is not justifiable, since conceptually, a Rectangle is-not-a Shape.




PreviousNext

Related