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 Java Data Structures Exploring the Java Collection Framework Meet the JCF

Still Confusing!!

what is basically interface? why to use it ? can we use import class instead of that?

2 Answers

An interface is like a class, except that (for current purposes) it only has abstract methods. If a class you write implements an interface, then it must make those abstract methods concrete, i.e., you must write code blocks for them. Why have them? One of the standard answers is that with interfaces you can have polymorphism without inheritance! Another is that by having your class implement an interface the compiler will make sure you do override those abstract methods. I.e., it will enforce the contract the interface represents. Another answer is that it is a way to have something like multiple inheritance without the problems of multiple inheritance. And there are other answers as well.

Thanks!!it helps me lot

An Interface is like minimum requirements for a class. If a class implements an interface it should implement or override all of the methods from the interface.