Sobes.tech
Middle

What methods can be contained in an interface?

sobes.tech AI

Answer from AI

  • Abstract methods (without implementation).
  • Static methods (with implementation).
  • Default methods (with implementation and the default keyword).
// Interface example
interface MyInterface {

    // Abstract method
    void abstractMethod();

    // Static method
    static void staticMethod() {
        System.out.println("This is a static interface method");
    }

    // Default method
    default void defaultMethod() {
        System.out.println("This is a default method");
    }
}
What methods can be contained in an interface? — Java - sobes.tech