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!
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
Stayl T968 Points
Difference between implementing and importing?
What is the purpose of using 'implements' on 'Comparable' and then using its compareTo() method? Can't we just import the class 'Comparable' and use the method as @override? We are using @override anyway!
I'm not sure if you already know this, but, Comparable is an interface, and not a Class.
You can both implement and import an interface. If you import an interface you don't have to implement it. But, if you implement an interface , you do have to import it if the interface is declared in a different package than the class that implements it.
Basically, what an import statement does, is it tells that file(package) what classes/interfaces are available to be used. But say, you had a main class that implements/imported the Comparable interface, if you were to make a class that extends your main class, but in a different package, that sub-class must also import the Comparable interface.
Let me know if this is confusing and I can try to re-explain.