No, we cannot declare an interface method static in java because interface methods are abstract by default, and static and abstract keywords can’t be used together.
Example
interface SubtractionTest { static void subtraction(int num1, int num2); } public class Main implements SubtractionTest { void subtraction(int num1, int num2) { System.out.println(num1 - num2); } public static void main(String[] args) { Main main = new Main(); main.subtraction(150, 100); } } |
Output
Main.java:3: error: missing method body, or declare abstract static void subtraction(int num1, int num2); ^ 1 error |
Java interview questions on interface and abstract class
- What is interface in java?
- Can we declare an interface method static in java?
- Can an interface be declared final in java?
- What is marker interface and how we can create it?
- What is difference between abstract class and interface in java?
- What is abstract class in java?
- Why abstract class is used in java?
- Can abstract class have constructors in java?
- Can abstract class be final in java?
- Can we declare local inner class as abstract?