Ch8: Interfaces and Polymorphism Flashcards
Define Interface
Formal construction allowing the creation of a set of behaviors a class must fulfill
Define Method Signature
Includes name, parameters, and return type of method, but no body
What is the default and only allowable access level of interface members
Public
___ methods only deal with universal behaviors not dependent on instance properties. Can contain code in its body.
Static
A class ____ an interface
Implements
Is it possible to create an instance of an interface
No, you may implement an interface, or declare variables and parameters as interface types
Name a benefit of using Interfaces
- You can implement many interfaces at once
- Can both extend class and implement interface simultaneously
- Make code usable in wider variety of contexts
- Decouple code using class from actual class types used
Abstract class
Class declared with abstract keyword. Can’t create an object from an abstract class. Can contain method signatures.
____ may contain non-constant fields, while ____ can only contain constant fields.
Abstract classes, interfaces
Comparable
Allow comparison—in a “greater than” and “less than” sense—to another instance of the class
Comparator
Compares two objects of a given class. To allow comparisons and ordering based on the different fields, you can create several different Comparator classes. The class for the compared objects does NOT implement the interface itself.
Iterable
Enables iteration over a collection of objects using a for-each loop
List
Enables access to objects in a collection by index. In other words, it enables ordered collections.
Map
Represents a collection of key/value pairs
Define paramaterized interface
Need to specify the class (ex: Comparable; Comparable would compare Job objects)