driteknight
driteknight

Reputation: 51

IS-A and HAS-A relationship occur together in OOPS

In Java every class is a child of Object. So a class IS-A Object. Now if it contains a data member of Object type (actually any type in this case), then it would be HAS-A relationship. Related to above statement I have following doubts. 1. Is there a name for this relationship, IS-A and HAS-A coming together? 2. Are there any real world example for it? 3. From OOPS perspective, is it okay to have this relationship or should be avoided?

Upvotes: 2

Views: 250

Answers (1)

Jose Martinez
Jose Martinez

Reputation: 11992

  1. Is there a name for this relationship, IS-A and HAS-A coming together?

No.

  1. Are there any real world example for it?
List<Set> aListThatContainsSets

List and Set are both Collections. In this example a List has a bunch of Sets.

  1. From OOPS perspective, is it okay to have this relationship or should be avoided?

Yes its fine. You can even HAS-A yourself.

public class MyClass{

     MyClass me;

}

Upvotes: 2

Related Questions