Golden rules about Java Interfaces

Below are some of the golden rules or facts about java interfaces where most of the developers do not make use or may be unaware of the same.

1.  This rule is the very basic one that every developer must know. All the fields of an interface are public, static & final by default.

java interfaces


java interfaces

2. In any interface, the methods declared are public by default.

java interfaces point2

3.  Any non-abstract classes has to override all the methods declared in the super interface.

java interfaces point 3

java interfaces point 3

Note : The Car class (non abstract class) will throw a compilation since it does not provide implementation for all the methods declared in the Vehicle interface.

4. An interface can never extend any class.

java interfaces point 4

5.  Nesting of interface is well supported in java.

java interfaces point 5

6. Methods in an interface cannot be declared as static and final.

java interfaces point 6

7. The concept of functional interface is an interesting one in java. A functional interface is nothing but an interface with only one method.

java interfaces point 7

8. Marker interface is an interface with no methods declared. E.g. Serializable interface in java.

9. An interface can also be nested under a class.

java interfaces point 9

Please follow and like us:

Questions? Comments? Suggestions? Let us know!! Like / Subscribe / Follow for more updates.