Ch8: Interfaces and Polymorphism Flashcards

1
Q

Define Interface

A

Formal construction allowing the creation of a set of behaviors a class must fulfill

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define Method Signature

A

Includes name, parameters, and return type of method, but no body

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the default and only allowable access level of interface members

A

Public

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

___ methods only deal with universal behaviors not dependent on instance properties. Can contain code in its body.

A

Static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A class ____ an interface

A

Implements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Is it possible to create an instance of an interface

A

No, you may implement an interface, or declare variables and parameters as interface types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Name a benefit of using Interfaces

A
  1. You can implement many interfaces at once
  2. Can both extend class and implement interface simultaneously
  3. Make code usable in wider variety of contexts
  4. Decouple code using class from actual class types used
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Abstract class

A

Class declared with abstract keyword. Can’t create an object from an abstract class. Can contain method signatures.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

____ may contain non-constant fields, while ____ can only contain constant fields.

A

Abstract classes, interfaces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Comparable

A

Allow comparison—in a “greater than” and “less than” sense—to another instance of the class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Comparator

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Iterable

A

Enables iteration over a collection of objects using a for-each loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

List

A

Enables access to objects in a collection by index. In other words, it enables ordered collections.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Map

A

Represents a collection of key/value pairs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Define paramaterized interface

A

Need to specify the class (ex: Comparable; Comparable would compare Job objects)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Give an example of an interface extending another interface

A

List extends Iterable, both of which are implemented by ArrayList class

17
Q

Describe a best practice for testing interfaces

A

Focus on testing the contract that the interface is supposed to be upholding as opposed to the interface itself