aspose file tools*
The moose likes Beginning Java and the fly likes Why methods in an interface cannot be static? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why methods in an interface cannot be static?" Watch "Why methods in an interface cannot be static?" New topic
Author

Why methods in an interface cannot be static?

Akhil kumarS
Greenhorn

Joined: Oct 16, 2007
Posts: 13
All methods in an interface are implicitly public, abstract, and never static. Why methods in an interface cannot be static?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Akhil kumarS
Greenhorn

Joined: Oct 16, 2007
Posts: 13
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.
 
subject: Why methods in an interface cannot be static?