This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes about interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about interface" Watch "about interface" New topic
Author

about interface

sunanda kadam
Ranch Hand

Joined: Feb 26, 2008
Posts: 42
Why interface methods are not static ?
though fields can be static .......
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1294

Hi sunanda,

method declarations of an interface are public abstract by default because there is no implementation and they have to be implemented by any concrete class which implements the interface. And abstract methods can't be static because they don't have an implementation which could be called

Marco
sunanda kadam
Ranch Hand

Joined: Feb 26, 2008
Posts: 42
still not cleared can you please elaborate more
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1294

You are allowed to assign a value to a field in an interface declaration so you can later use this field as a static constant.

But you can't give an implementation for a method in an interface declaration because methods in an interface are abstract by default: abstract = NO implementation!!! So it's obvious that such a method can't be static at the same time because you are allowed to call static methods but you are not allowed to call abstract methods!

Anyway the main reason for interfaces is to define abstract method prototypes which have to be implemented by any concrete class to fulfill the contract of the public API of the interface. So it doesn't make sense to define method implementations in an interface.

Now better?

Marco
sunanda kadam
Ranch Hand

Joined: Feb 26, 2008
Posts: 42
Thanks Marco
Now its cleared.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: about interface
 
jQuery in Action, 3rd edition