Java OCA OCP Practice Question 413

Question

Consider this code:

interface Interface1{  } 
interface Interface2{  } 
class A  {  } 
class B extends A implements Interface1{  } 
class C extends B implements Interface2{ 
   D d = new D (); 
} 
class D  {  } 

Which of the following statements are true?

Select 3 options

  • A. D is-a B.
  • B. B has-a D.
  • C. C is-a A
  • D. C is-a X 1
  • E. C is-a Interface2


Correct Options are  : C D E

Note

Consider this code:

class A extends B implements I{ 
  D d = new D (); 
} 

Inheritance defines an is-a relation , so A is-a B because A extends B.

This actually means that A can be used in all the places where B is used.

A can substitute for B anywhere because A is-a B.

As all objects have Object as their super class, every object 'is-a' Object.

Since A implements I, it is sometimes said that A 'is-like-a' I.

Although A is not a I but for all purposes A is like an I.

The distinction between is-a and is-like-a is not important for the exam.

For the purpose of the exam, is-like-a is same as is-a.

Aggregation defines a has-a relation.

Here, D is a member object in A so D is contained in A.

So it is said that A 'has-a' D.

All Java objects have the class Object as the ultimate superclass, and so Object is always at the root of any inheritance hierarchy.




PreviousNext

Related