This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes what is the significance of static while declaring constant. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is the significance of static while declaring constant." Watch "what is the significance of static while declaring constant." New topic
Author

what is the significance of static while declaring constant.

kish kumar
Ranch Hand

Joined: Jan 03, 2008
Posts: 54
what is the significance of static while declaring constant.

why java made it implicitly static .

suppose if java not made it static it will be available to all objects of class implementing interface with an individual copy.

if it is static all objects share common copy.

since it is final even though it is not static ,no object can modify it and no harm.so why static really required?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
More of a beginner's question.

If it is constant, and intended for use by many instances, why do you want several copies? If the value of BOILING_POINT is always 100, why should each Water object need its own copy? They can share the static field and save memory.
It also means that BOILING_POINT is available to other classes without having to create a Water instance.
kish kumar
Ranch Hand

Joined: Jan 03, 2008
Posts: 54
Thanks Ritchie
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the significance of static while declaring constant.
 
Similar Threads
declaring constant variable in java
Interface variables
static class!
Class Loading
better code for try and catch