5

I have a interface and abstract class.

public class TEST extends Abstract implements Inter2{
    void print() {
        toDO();
    }

    public static void main(String[] args) {
        new TEST().toDO();
    }
}

abstract class Abstract {

    public void toDO() {
        System.out.println("Abstract is called");
    }
}

interface Inter2 {

    default void toDO() {
        System.out.println("Inter2 is called");
    }
}

I want to force class interface default methods instead of abstract class.

Tagir Valeev
  • 97,161
  • 19
  • 222
  • 334
Siva Kumar
  • 1,983
  • 3
  • 14
  • 26

1 Answers1

7

You'll have to override toDO in the TEST class:

@Override
public void toDO() {
    Inter2.super.toDO();
}
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Java is quite logical here - for you can implement multiple interfaces, that is why you have to prefix super. If super is alone, then it refers to the only one superclass that can be extended. – gilyen Jun 13 '22 at 06:30