Interfaces Flashcards

1
Q

What are interfaces?

A

Ways to define how parts of a program communicate with other parts

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

How can you make a class use an interface?

A

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

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

What is the purpose of interfaces?

A

Encapsulation: we separate the public interface from the private implementation. It enables us to use the class without having to know how it works.

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

What is an API?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you define an interface?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can you implement the comparable interface?

A

class Object implements Comparable<object></object>

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