Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why methods in an interface cannot be static?  RSS feed

 
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
Posts: 20893
81
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!