Static Interface Methods Flashcards

1
Q

What is the difference between a static method in a class and a static method in an interface !

A

The difference between a static method in a class and a static method in an interface is that a static method in an interface is not inherited by any class that implements the interface

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

Give static interface method rules !

A

Here are the static interface method rules you need to be familiar with:

  1. Like all methods in an interface, a static method is assumed to be public and will not compile if marked as private or protected.
  2. To reference the static method, a reference to the name of the interface must be used.
  3. in Java 8 and later versions, if you declare a static method inside an interface, you are required to provide a method body for it. This applies to both static methods and default methods (which were introduced in Java 8).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens if a class implements two interfaces containing static methods with the same signature ?

A

A class that implements two interfaces containing static methods with the same signature will still compile at runtime, because the static methods are not inherited by the subclass and must be accessed with a reference to the interface name.

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