wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why interface methods are not 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 interface methods are not static ?" Watch "Why interface methods are not static ?" New topic
Author

Why interface methods are not static ?

ragi singh
Ranch Hand

Joined: Mar 10, 2010
Posts: 198

Hi all,
can anyone explain why the interface methods are not static .
As far as i understand interface methods are implemented in the implementation class . So the implementation class will be the one ultimately having the static method associated .
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

static methods are not associated with a class. So an interface with a static method that no class can implement would be of no use.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

ragi singh wrote:
As far as i understand interface methods are implemented in the implementation class . So the implementation class will be the one ultimately having the static method associated .

Then, could you expect the polymorphic behavior with that?


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3254
    
    2
ragi singh wrote:Hi all,
can anyone explain why the interface methods are not static .

Interfaces do not support static methods because the language designers did not think it was a good or useful idea. Otherwise, there is no reason why an interface can't be designed to have declarations for static methods. Afterall, they do allow you to declare static fields.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

I think you may be confusing static with abstract.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi Ragi Singh,

If interface methods are static, you cannot have polymorphic behavior in your implementation classes. To avoid that, interface methods cannot have static methods.


OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why interface methods are not static ?
 
Similar Threads
Interfaces Cannot have static methods??
interfaces and locks
hy interface sad and class apple can be static when methods are not allowed 2b stati.
Static Methods in an Interface
interfaces