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 Organizing Data Interfaces

Aditya Puri
Aditya Puri
1,080 Points

Didn't understand

I didn't exactly understand what interfaces are. I read the java oracle tutorials- https://docs.oracle.com/javase/tutorial/java/concepts/interface.html

But if interfaces are a group of methods then aren't they the same as a class? What is different about them?

Aditya Puri
Aditya Puri
1,080 Points

i also can't seem to understand what implementing means..

Tyler Combs
Tyler Combs
15,525 Points

After I read your question, it made me curious myself what exactly the differences are between a class and an interface. I'm right at the same part as you in the course. I found a great link that explains things well and caused me to understand things better as well!

http://www.cs.carleton.edu/faculty/rkirchne/cs217/tocej-proj/classes.html

Aditya Puri
Aditya Puri
1,080 Points

it really helped me too! Thanks for sharing this link!!

1 Answer

Hi folks

Think of an interface as a contract that helps you group functionalities (related methods) into one "Package" without forcing an implementation on you.

So ... Interfaces ... tells these are the methods signatures, and it up to you how to implement them ... you implement an interface and it up to you how to implement. Classes ... if you inherit a class ... you are inheriting the whole bucket load of predefined methods, unless you explicitly override.

but interfaces offers something far more interesting.

Let say you have Class A and Class B, each has a set of methods you would like to implement in your new Class C. You can either inherit from A or B, but not both.

With interfaces, Let says you have Interface A and Interface B. Now you have a Class C and you want to implement Both interfaces A and B ... no problem.... just implements A, implements B in your new class

Hope this helps.

Please mark question as answered if this answers your question.