asked 203k views
3 votes
Give an example of an IS-A (inheritance) relationship and a separate example of a HAS-A (composition) relationship within the fields of either mathematics, biology, or engineering. The example should be different from one given in class. Explain why these are appropriate examples.

1 Answer

6 votes

Inheritance (is-a) relationships are derived child classes that inherit attributes and methods from their parent class. Composition (has-a) relationships are classes whose attributes are comprised of other classes. Each relationship has its advantages and disadvantages. See the link below for best uses of each.

For example:

class Animal { }

class Dog extends Animal { }

This means Dog IS-A animal

2. HAS-A simply means reference

For example:

class Nip { }

class Dog { private Nip nip;}

This means Dog HAS-A Nip

Hope this helped!! :)

answered
User Cameron Martin
by
7.6k points

No related questions found

Welcome to Qamnty — a place to ask, share, and grow together. Join our community and get real answers from real people.