A member is indeed implicitly static. This just means that it is static without explicitly specifying the static modifier. Good form also mandates that you should never explicitly specify redundant modifiers (that apply to all type declarations (class, interface, annotation, enum) and their members, not just interfaces).
OK, to be clear - the original question was not about members inside an interface. It's about the interface itself, assuming it's nested inside another class or interface. A member interface is an interface that is a member of some other class or interface - and yes, member interfaces are implicitly static. (Mostly because there's no real use for a "this" reference inside an interface, so there's be no benefit to having a non-static interface.)
"I'm not back." - Bill Harding, Twister
Soni Prasad
Ranch Hand
Joined: Mar 09, 2005
Posts: 97
posted
0
thanx Jim Yingst for clearifying my question. thanx Jeroen Wenting for a good example.
Tony Morris
Ranch Hand
Joined: Sep 24, 2003
Posts: 1608
posted
0
A member interface is implicitly static.
An interface member is not a constant - it is public static and final. This is not the same as a constant. A final is not synonymous with a constant.
is clearly final, but it's not constant since anyone can change the contents of the StringBuffer at any time. The precise rules for what constitues a compile-time constant in Java are given in JLS 15.28.
You should note that this kind of question will not be on your exam.
Vishnu Prakash
Ranch Hand
Joined: Nov 15, 2004
Posts: 1026
posted
0
An interface member is not a constant - it is public static and final. This is not the same as a constant.
In Kathy Sierra & Bert Bates book it is given as(Page 115)
All variables defined in an interface must be public, static and final - in other words interfaces can declare only constants and not instance variables.
Can u both confirm this.
Tony your example is phenomenal.
Jim the example which u had given helps to understand it is not necessary for a final variable to be constant all the time. But I want to know whether a interface variable which is implicitly final is a constant or not.
Jim if you can give simple examples for these statements it will of great help.
# Simple names that refer to final variables whose initializers are constant expressions # Qualified names of the form TypeName . Identifier that refer to final variables whose initializers are constant expressions
Tony Morris
Ranch Hand
Joined: Sep 24, 2003
Posts: 1608
posted
0
All variables defined in an interface must be public, static and final - in other words interfaces can declare only constants and not instance variables.
Can u both confirm this.
I can confirm that this is incorrect. Books are wrong all the time - they are not an eternal truth.