Java Interfaces Flashcards

1
Q

In general, what are Java interfaces?

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

What is the problem with single inheritance in Java?

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

What do we actually get when we inherit form a class like OrderedItem?

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

What is the examplanation of a Java interface?

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

What is an example for the code to create an interface called Measurable with a method getMeasure();

Explain how it works in general

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

How would you use the attached interface?

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

How do abstract classes and interfaces differ?

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

How do interfaces and types work?

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

More specifically, what’s the difference betwen an abstract class and an interface?

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

Why use an interface?

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

Explanation:

We’re not inheriting from any Class here- we’re inheriting from multiple Interfaces.

This in turn is only supplying us with demands we have to satisfy.

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

In general how does Polymorphism work with Interfaces?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. New in Java 1.8, what does “default” do for an interface?
  2. Why was this added?
A
  1. If an interface extends another that has a default method, it can redeclare (as abstract), override, or leave implementation.
    1. A class can get default behavior or change it.
  2. See the image below:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Whe you have default methods, how do problems with multiple inheritance work?

A
  • Suppose interfaces Int1 and Int2 both implement getIt( ) as a default method, different behaviors.
  • What happens if Class1 implements them both?
    • Not allowed, compile-time error:
      • errro: class Class1 inherits unrelated defaults for getIt( ) from types Int1 and Int 2
  • But: Class1 can define a new behavior for getIt( );
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Other than inheritance problems, what are other errors with default (jave 1.8 Interfaces)

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

For Interfaces (in Java 1.8) how does the static keyword work?

A