Use default methods is to declare optional methods in an interface. - Java Object Oriented Design

Java examples for Object Oriented Design:interface

Description

Use default methods is to declare optional methods in an interface.

Demo Code

interface Named {
    void setName(String name);
    /*from w w w .ja  va 2 s  . com*/
    default String getName() {
        return "John Doe";
    }
    
    default void setNickname(String nickname) {
        throw new UnsupportedOperationException("setNickname");
    }
    
    default String getNickname() {
        throw new UnsupportedOperationException("getNickname"); 
    }
}

Related Tutorials