0
public interface A{
  default void decorateWithPaints(){
    System.out.println("Decorate in A using paints");
  }
}

public interface B{
  default void decorateWithPaints(){
    System.out.println("Decorate in B using paints");
  }
}

public class C implements A,B{
  @Override
  public void decorateWithPaints() {
    A.super.decorateWithPaints();
  }
}

A.super.decorateWithPaints() what does this actually means??? We know that we can access super class method using super keyword . But in this case we have to give interface name to access default interface method. It is really confusing me.

Andy Turner
  • 137,514
  • 11
  • 162
  • 243
  • 2
    It means: invoke the default implementation of the method from `A`. Otherwise, it's ambiguous, because there are two super interfaces implementing the method. – Andy Turner Feb 01 '17 at 08:48
  • Is it compiling ? Implementing two interfaces with a similar method with default. I though it was not permited – AxelH Feb 01 '17 at 08:50
  • @AxelH see http://stackoverflow.com/a/19976615/3788176. Probably the case you're thinking of is where the method isn't overridden in the concrete class. – Andy Turner Feb 01 '17 at 08:51
  • @AndyTurner right, thanks ! So indeed, this is obviously to precise witch implementation to use, this was not a problem in Java since multiple inheritance was not permitted, but now that interface have implementation too, this could be ambigous. – AxelH Feb 01 '17 at 08:54
  • Actually i mean Interface with super keyword means what? – Touhidur Rahaman Khan Feb 01 '17 at 09:22

0 Answers0