| Author |
Variables in interface
|
Rajasekar Elango
Ranch Hand
Joined: Sep 13, 2004
Posts: 105
|
|
Hi, I know the variables in interface are public static final by default and a top level interface should also be public. Now my question is to use interface only declare/use constants (not any methods) we can use it from anywhere by using interfacename.variable, but will there be any situation where we want to implement that interface just to use final variables..? Thanks, Raja
|
SCJP 1.4
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
|
It is possible to "implement" an interface, just to get the constants defined therein. However, it is generally agreed to be bad practice.
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
Mike Gershman
Ranch Hand
Joined: Mar 13, 2004
Posts: 1272
|
|
|
If you are using Java 5, static imports allow you to selectively import just the constants you need from an interface or class. Java purists consider imports ending in .* to be a crude instrument. Implementing an inteface just to acquire its constants would be similarly deprecated.
|
Mike Gershman
SCJP 1.4, SCWCD in process
|
 |
Rajasekar Elango
Ranch Hand
Joined: Sep 13, 2004
Posts: 105
|
|
Thanks for your replies.. - Raja
|
 |
 |
|
|
subject: Variables in interface
|
|
|