Static Methods in Interface are those methods, which are defined in the interface with the keyword static. Unlike other methods in Interface, these static methods contain the complete definition of the function and since the definition is complete and the method is static, therefore these methods cannot be overridden or changed in the implementation class.
Similar to Default Method in Interface, the static method in an interface can be defined in the interface, but these methods cannot be overridden in Implementation Classes. To use a static method, Interface name should be instantiated with it, as it is a part of the Interface only.
Below programs illustrate static methods in interfaces:
Program 1: To demonstrate use of Static method in Interface.
In this program, a simple static method is defined and declared in an interface which is being called in the main() method of the Implementation Class InterfaceDemo. Unlike the default method, the static method defines in Interface hello(), cannot be overridden in implementing the class.
Hello, New Static Method Here Hello, Override Method here
Program 2: To demonstrate Scope of Static method.
In this program, the scope of the static method definition is within the interface only. If same name method is implemented in the implementation class then that method becomes a static member of that respective class.
Called from Interface PrintDemo Called from Class
- Understanding "static" in "public static void main" in Java
- Static and non static blank final variables in Java
- Static Block and main() method in Java
- static keyword in java
- Static class in Java
- Static blocks in Java
- Static import in Java
- Static Control Flow in Java
- Shadowing of static functions in Java
- Final static variable in Java
- Comparison of static keyword in C++ and Java
- Static vs Dynamic Binding in Java
- Map Interface in Java
- Java 8 | IntToDoubleFunction Interface in Java with Examples
- Java 8 | DoubleToLongFunction Interface in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.