| 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: 1221
|
|
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: 1221
|
|
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.
|
 |
 |
|
|
subject: about interface
|
|
|