wood burning stoves
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why can Watch "why can New topic

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.


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: 255

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.

Salil Verma
Have you checked out Aspose?
subject: why can't interface methods be static?
It's not a secret anymore!