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

Ezekiel dela Peña
Ezekiel dela Peña
6,231 Points

When to use Interface or Abstract?

As the title said, When to use the interface vs. the abstract?

Can you give me an real world experience for this one?

1 Answer

Brian Spinos
Brian Spinos
15,722 Points

Interfaces are like contracts: when a class implements an interface, it promises to implement the methods that are in the interface, an Abstract class in like a glorified interface, as it can do the same as the interface, but it also can implement its own methods, the down side of Abstract classes is that your class can only inherit from one other class (be it abstract or not) so Better to go with the interface, as your class can implement as many interfaces you want!