Private Interface Methods

Java-Private Interface Methods

Private Interface Methods

Beginning with JDK 9, an interface can include a private method. A private interface method can be called only by a default method or another private method defined by the same interface. Because a private interface method is specified private, it cannot be used by code outside the interface in which it is defined. This restriction includes subinterfaces because a private interface method is not inherited by a subinterface.

Program

Private Interface Methods Private Interface Methodss

Program Source

interface Facebook {
    
    default void login() {
        
        chatting();
    }
    private void chatting() {
        
        System.out.println("Chatting....");
    } 
}
class UserOne implements Facebook {
    
    public void login() {
    
        System.out.println("Login Successfully");
        Facebook.super.login();
    }
}
public class Javaapp {

    public static void main(String[] args) {
        
        UserOne user = new UserOne();
        user.login(); 
    }
}

Leave a Comment