Java Interfaces
Interfaces:
- Applying an interface requires that a class has the named functions defined
- It's similar to inheritance but you use the "implements keyword instead of "extends"
- This is useful if you want to make an array of different classes that share the function(s) specified in the interface
- Multiple interfaces can be applied to a class (just add the other interfaces after "implements", separating each with a comma)
Grouping Objects With a Shared Interface
- This is useful if you have a variety of class types, but you need them all to answer to perform a certain action in their own way (such as 'display')
Challenge
Create two classes (Teacher and Student) that apply an interface requiring them to have a getId function. Then, define that function within each of the classes. Finally, create an array that contains objects of both class types (Teacher and Student).