Java Interfaces Flashcards
In general, what are Java interfaces?
What is the problem with single inheritance in Java?
What do we actually get when we inherit form a class like OrderedItem?
What is the examplanation of a Java interface?
What is an example for the code to create an interface called Measurable with a method getMeasure();
Explain how it works in general
How would you use the attached interface?
How do abstract classes and interfaces differ?
How do interfaces and types work?
More specifically, what’s the difference betwen an abstract class and an interface?
Why use an interface?
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.
In general how does Polymorphism work with Interfaces?
- New in Java 1.8, what does “default” do for an interface?
- Why was this added?
- If an interface extends another that has a default method, it can redeclare (as abstract), override, or leave implementation.
- A class can get default behavior or change it.
- See the image below:
Whe you have default methods, how do problems with multiple inheritance work?
- 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
- Not allowed, compile-time error:
- But: Class1 can define a new behavior for getIt( );
Other than inheritance problems, what are other errors with default (jave 1.8 Interfaces)