[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

private static final

hi all, please tell me why to use private static final in front of variable ? If the variable is final, its value will be constant in that class. So what is the need of static keyword because if the variable is static, it has only one instance throughout the class.... Please explain.
0
jayz_smith
Asked:
jayz_smith
  • 2
  • 2
1 Solution
 
nordtorpCommented:
Please have a look at this explanation:

Java  Final vs. Static Variable
http://kwang.blogdns.com/tech/java-final-vs-static-variable.html

Ask me if something is unclear and I will try to explain
0
 
jayz_smithAuthor Commented:
@ nordtorp :  Thanks for the wonderful link. Only one question.  " Before Java can create an instance of a class, it must first load and initialize that class. One step of class initialization is assigning values to all its static fields " this is what the link says. But my question to you is, what if there is no static fields in the class ? how would that class get initialize by java ?
0
 
jayz_smithAuthor Commented:
perfect answer
0
 
nordtorpCommented:
It just says that one step of class initialization is assigning values to all its static fields, if there are no static fields, it does not need to assign anything.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now