Java OCA OCP Practice Question 3005

Question

Consider the following program:

class ClassA {}/*from ww  w. j ava 2  s . c  o m*/

interface InterfaceB {}

class ClassC {}

class Main extends ClassA implements InterfaceB {
    String msg;
    ClassC classC;
}

Which one of the following statements is true?

a)   Class Main is related with ClassA with a haS-a relationship.
b)   Class Main is related to ClassC with a composition relationship.
c)   Class Main is related with String with an IS-a relationship.
d)   Class ClassA is related with InterfaceB with an IS-a relationship.


b)

Note

When a class inherits from another class, they share an IS-a relationship.

on the other hand, if a class uses another class (by declaring an instance of another class), then the first class has a haS-a relationship with the used class.




PreviousNext

Related