Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why methods in an interface cannot be static?

 
Akhil kumarS
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All methods in an interface are implicitly public, abstract, and never static. Why methods in an interface cannot be static?
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static methods are NEVER overridden. Instead, if you define a static method with the same name, return type and parameters as is defined in a superclass, you will hide that method.

Because static methods cannot be overridden, they need to have an implementation. But interfaces do not allow implementation of methods.

If an interface would allow static methods, this would lead to a situation similar to a final abstract method - the method is abstract, but it can never be implemented.
 
Akhil kumarS
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Rob Prime,You explained the things in a nice simple way....
Once again thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic