Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Will Interfaces always/sometimes satisy is-a relationship

I understand Interface is like a contract and inheritance is a parent-child relationship.

But my question stems from the fact that

  1. Inheritance always satisfies is-a relationship.
  2. If I look at some examples like List, Array List in Java. ArrayList satisfies is-a relationship with its interface.

My questions:

  1. Can we say Interface satisfies is-a relationship as well (may be sometimes). In those cases, how do we know when to use Interfaces and when to use Inheritance.?
  2. Is Interface also the extended idea of Inheritance concept?

Using interfaces you implement in the class a model to be follow. So you just have empty methods and in the class you need to write the code for every method. All the methods in the interface have to be implemented in the class.

In inheritance you offer the hole method. You just uses it. But you use the method if you need so.

There is the abstract class too. It is similar to the interface. But in the abstract class you can have methods that are not abstract and you can write the hole code in it.

Hope I could help.