0

In case of multiple inheritance with abstract class and interface. Abstract class dance() is called.why is the priority given to abstract class method but not default method in interface.

public class Child extends Absclass implements Interfc{
    public static void main(String[] args){
    Child c = new Child();
    c.dance();
    }
}
Abstract class Absclass{
    public void dance(){
    System.out.println("abstract dancing");
    }
}
Interface Interfc{
    default public void dance(){
    System.out.println("interface dancing");
    }
}
  • 1
    Isn't that just the rules of the language? You've provided an implementation of `dance()`, so there's no need to invoke the default method. What would be the benefit of the alternative approach? – Kevin Boone Oct 10 '20 at 14:52
  • See the accepted answer in https://stackoverflow.com/questions/32471220/super-class-method-and-interface-default-method-conflict-resolution for why this is the case. It's basically a defined rule in JLS. – Cihan Oct 10 '20 at 14:57

0 Answers0