0

What is main difference between is-a and has-a relationship in java ?

give an example also.

6th Jun 2017, 6:01 AM
Chandresh Solanki
Chandresh Solanki - avatar
2 Respuestas
+ 3
a cat IS an animal a cat HAS eyes (but a cat isn't an eye or an eye isn't a cat) When you define your classes, the class Cat can inherit from the class Animal because a Cat IS an animal, the cat possesses all the characteristics of an animal like making a sound, the ability of eat, to drink. There is nothing an animal in general can do that or has the cat is unable to do or hasn't. (But they might be things a cat do or has and that all the animal can't do or haven't). Then a cat has an eye, so in the class of Cat you can define a member of type Eye, it's an attribute of the class Cat.
6th Jun 2017, 6:07 AM
Glozi30
Glozi30 - avatar
0
Is-a relationship represents inheritance while has-a relationship represents aggregation.for example BMW is a car BMW has engine. Here car is parent class BMW extends car. BMW has engine it represents aggregation
6th Jun 2017, 8:40 AM
Pankaj
Pankaj - avatar