No, we cannot declare final interface in java because its implementation is provided by another class and final interface can not be implemented.
Example
final interface SubtractionTest { void subtraction(int num1, int num2); } public class Main implements SubtractionTest { public 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:1: error: illegal combination of modifiers: interface and final final interface SubtractionTest { ^ Main.java:7: error: cannot inherit from final SubtractionTest public class Main implements SubtractionTest ^ 2 errors |
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?