File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes interface 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 "interface" Watch "interface" New topic


Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
i got a question in whizlabs mock test that can interface have static methods? i said cant....but why?

is it because if we had static method in interface it would be empty....and static methods cant be inherited

are there are any other reasons too?

Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Reason is the purpose why Interface has been designed.
Interface can just say what to do not how to do.
So it can only declare any method (what to do), cannot give body(how to do) to them.
There is no declaration for static methods, as static methods are class methods, not instance methods.

J.Augusto Gomes

Joined: Jul 18, 2004
Posts: 1

only to member interfaces !

Oss !

Rio de Janeiro, Brazil.
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Every method declaration in the body of an interface is implicitly abstract and static methods cannot be abstract.
@J.Augusto: welcome to Java Ranch
I agree. Here's the link:
subject: interface
It's not a secret anymore!