Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the significance of static while declaring constant.

 
kish kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49771
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ritchie
 
Campbell Ritchie
Sheriff
Pie
Posts: 49771
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic