Interfaces Flashcards
What are interfaces?
Ways to define how parts of a program communicate with other parts
How can you make a class use an interface?
use the keyword implement. If you do this, you must write methods in the class that match the signatures of the methods defined in the interface, and they must be explicitly public
What is the purpose of interfaces?
Encapsulation: we separate the public interface from the private implementation. It enables us to use the class without having to know how it works.
What is an API?
An Application Programming Interface: defines an interface that is published for different programs to use. (System.out.println is called from the Java API)
How do you define an interface?
Like you would define a class, except replace the word class with interface. Then you describe methods that do tasks, without specifying how those tasks are done. All the methods in the interface should be implicitly public. There are no variables
How can you implement the comparable interface?
class Object implements Comparable<object></object>