Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

interface in java

interface Interface {
        
    int INT_CONSTANT = 0; // it's a constant, the same as public static final int INT_FIELD = 0
        
    void instanceMethod1();
        
    void instanceMethod2();
        
    static void staticMethod() {
        System.out.println("Interface: static method");
    }
        
    default void defaultMethod() {
        System.out.println("Interface: default method. It can be overridden");
    }

    private void privateMethod() {
        System.out.println("Interface: private methods in interfaces are acceptable but should have a body");
    }
}
Static, default, and private methods should have an implementation in the interface!
Source by cse.iitkgp.ac.in #
 
PREVIOUS NEXT
Tagged: #interface #java
ADD COMMENT
Topic
Name
4+2 =