Chapter 20: Interfaces, Including Generic Interfaces Flashcards

1
Q

How can a type parameter extend an interface?

A

Bind the type parameter so that the type may be a class that implements the interface, the interface itself or an interface that extends it

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

A class is a type and has three components:

A

Set of values (set of objects that are instances of the class)
Operations that can be performed on those values (instance methods)
Operation interfaces to those operations (method interfaces)

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

How does binary search work?

A

If items are sorted in a known total order.
Two indices, high and low.
look half way, if less low = middle, if high high = middle, if found found.
If low and high meet, not present

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

What is a total order?

A

A relationship between pairs of data that enables it to be sorted.
Anti symmetric, transitive, total

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

Describe multiple inheritance. What is the problem?

A

I can appear natural to view a class as a subclass of more than one superclass, inheriting properties from each superclass

Problem:
Ambiguity (if two superclasses contain a method of the same signature)
Run time efficiency (dynamic method binding- would have to search all trees to find method)

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

What is an interface? What are the rules?

A

Like a class except all instance methods are abstract and only method interfaces are declared (signatures and return types)

Rules:
contains a list of instance method heading with no body
All instance methods public
Cannot contain constructor methods
No class methods
No private instance methods or variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is interface a type?

A
Set of all references to objects that are instances of a class that implements interface
operations are methods implementations of instance methods
Operation interfaces is the method interface defined in the interface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do we implement a method?

A

A non abstract class that implements an interface must supply method implementations for the abstract methods defined in the interface

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

What is a generic interface?

A

An interface with type parameters. Type parameters may be used as types in the declaration of abstract methods

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

How can an interface extend an interface?

A

An interface can extend another (and many other) interface(s). Abstract methods and class constants are inherited.

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

Can a class implement many interfaces?

A

Yes. List with commas after “implements”

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

What is a generic method?

A
A method with type parameters <> before return type. May be defined in generic or non generic classes. May be class or instance methods- more useful as class methods.
class.mymethod(paramters)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What class methods does java.util.Arrays provide?

A

Sort- takes array of objects that it sorts into natural ordering. Items must be comparable.
Copy of- generic method. Takes array and new length

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

What is comparable?

A
If a class implements comparable, the class provides compare to enabling objects to compare with a given other.
compareTo provides natural ordering
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the relationship between compare to and equals?

A

equals should always be the same as compareTo(x) == 0

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