3

Why can't we create an interface with default static method?

public interface StaticTest {    
  default static void display() {    
     System.out.println("Display here");  
  }  
}
3
  • 3
    why would you want to create a default static method? Commented Feb 2, 2016 at 23:06
  • I want to add a feature in interface which can be directly access by classes that implement it without affecting the past implementations. Commented Feb 2, 2016 at 23:11
  • 1
    then you want either a default method or a static method Commented Feb 2, 2016 at 23:13

1 Answer 1

13

Static methods cannot be overridden or inherited in any meaningful sense, and default methods are there to be overridden or inherited. Just like other non-static interface methods, but default specifically implies that inheritance is meaningful to this method, which is incompatible with static.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.