This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Why is interface constant static Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why is interface constant static" Watch "Why is interface constant static" New topic
Author

Why is interface constant static

Prabu JayaPandian
Greenhorn

Joined: Aug 04, 2008
Posts: 8
We declare interface constants as public static and final. I understand why we declare them as public and final. But why do we make them static?
[ August 04, 2008: Message edited by: Prabu JayaPandian ]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Because if they weren't static, they would belong to instances. First of all, that means data replication - all instances of all implementing classes will have the exact same constant variables.
Second of all, instance variables are part of the implementation, and interfaces can have no implementation.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Why is interface constant static
 
Similar Threads
Interface variables
Inner Class in the Interface
why interface variables are static and final. what is reason to declare them as like that?
Interface
Non-final member variables in interfaces