Can We Declare an Interface Final in Java?

No, we can not declare interface as final. Interface in Java is similar to a class but it contains only abstract methods and fields, which are final and static. Since all the methods are abstract; therefore, we cannot instantiate interface. To use it, we need to implement the interface using a class and provide body to all the abstract methods int it.

If we make an interface final we will not be able to implement its methods, which defies the very purpose of the interfaces. Therefore, we cannot make an interface final in Java.

For experiment, if we try doing so, a compile time exception is generated. Let's try compiling the following piece of code

public final interface FinalInterface {
    public static final int number = 10;
    public abstract void demoMethod();
}

Above Java code will throw error : Illegal modifier for the interface FinalInterface; only public and abstract are permitted.

Hope we have enjoyed reading this post. Please do write us if we have any suggestion/comment or come across any error on this page. Thank we for reading!



Share this page on WhatsApp

Get Free Tutorials by Email

About the Author

is the founder and main contributor for cs-fundamentals.com. He is a software professional (post graduated from BITS-Pilani) and loves writing technical articles on programming and data structures.