Java Language Class, Abstract class and Interface method precedence


Example

Implementations in classes, including abstract declarations, take precedence over all interface defaults.

public interface Swim {
    default void backStroke() {
        System.out.println("Swim.backStroke");
    }
}

public abstract class AbstractSwimmer implements Swim {
    public void backStroke() {
        System.out.println("AbstractSwimmer.backStroke");
    }
}

public class FooSwimmer extends AbstractSwimmer {
}

The following statement

new FooSwimmer().backStroke();

Will produce

AbstractSwimmer.backStroke

public interface Swim {
    default void backStroke() {
        System.out.println("Swim.backStroke");
    }
}

public abstract class AbstractSwimmer implements Swim {
}

public class FooSwimmer extends AbstractSwimmer {
    public void backStroke() {
        System.out.println("FooSwimmer.backStroke");
    }
}

The following statement

new FooSwimmer().backStroke();

Will produce

FooSwimmer.backStroke