Tuesday, April 4, 2006 12:07 AM
Its really nice doubt..
First of all, the interface can not
have any state (i.e, instance variables), reason is as follows.
Before we dick deeper in to this
discussion we need to brush up our OOPs statements now,
1. Class has state and behavior.
State is a value holder , it's value
will change.[i.e instance variable]
Behavior means how the class should
act when some action triggered to the class[i.e methods
So, if any entity (in opps) which
has above two behavior can be act as class.
Now, I'm coming to your doubt.
First you have to understand one thing
that is, Interface is not a class. So it should not have any
state(i,e instance variable) and it's own behavior ( as you know,
interface does not have any method implementation, only it has method
template, class which is gonna be implement it will have to write a
implementation code for the method template)
so, If interface allow us to declare a
non-final variable, it'll be act as a instance variable. Thats why
the interface's fields are always final.[as you know, final variables
are not a instance variable as per OOPS]
[Interfaces are just a interface among
its implementations, since its not a class is should not have any
state and behavior]
Friend i jst gave some abstract
information, if you refere come opps related books you can get more
clear-cut idea about this topic.
my friend, hope i have clarified your
if not, feel free to ask me..