wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why can't interface methods 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why can Watch "why can New topic
Author

why can't interface methods be static?

Rachel Glenn
Ranch Hand

Joined: Oct 24, 2012
Posts: 95
I know that interface methods are implicitly public and abstract. Interface variables must always be public, static and final. Is there a specific reason interfaces can't have static methods?
Leena Diwan
Ranch Hand

Joined: Jun 18, 2001
Posts: 351
static means 'one per class'
Usually we mark a method 'static' in a class and can call it without having to make an instance of that class.

In case of interfaces, where is the body of the method?
What will it execute, even if it is allowed.
If the methods of an interface are implicitly 'abstract' it means that the method body is not there.

HTH


[SCJP2, SCWCD1.3, SCBCD]
Leena Diwan
Ranch Hand

Joined: Jun 18, 2001
Posts: 351
Check some discussions on similar lines here
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 254

Hey Rachel,

All methods of interface of implicitely abstract, whcih should be overridden by the implementing class. As the static method can not be overridden, interface does not allow creation of static methods.

If you want to have some static method in your parent class, you can think of considering abstract class as the parent rathen than interface.


Regards
Salil Verma
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why can't interface methods be static?