Unit_9: Java Interfaces Flashcards

1
Q

What is Java interfaces?

A

An Interface in Java is a structure that lists (public)
methods that are to be required by classes that
implement the interface

Every method is public and abstract automatically in
an interface

There are no true data members (not in the sense of
inherited variables anyway – any data members we
declare are implicitly public, static, and final, i.e.
class-level constants)

There is no restriction on the number of Interfaces a
Class implements

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

What is powerful feature of interface?

A

An interface acts like a type, just as a class does!

=> So not only can we implement Measurable, we can
have variables of type Measurable! (or parameters,
return types, etc.)

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

What is default methods?

A
  • Defined in an interface:
    default int getSomething() { … }
  • A default method has code!
  • If an interface extends another that has a default
    method, it can redeclare (as abstract), override, or
    leave implementation unchanged
  • An implementing class can keep the default
    behaviour or change it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly