This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes static final vars Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "static final vars" Watch "static final vars" New topic

static final vars

Vinay Gangoli

Joined: Jun 13, 2003
Posts: 22
Hi all,
1) I believe a member variable ( say int) that is declared as final has to be initialized in a initializer block or a constructor. Is that right?

2) Can i do the same with a member variable declared as static final ?
This must be pretty common, but i am kinda confused abt it ...please comment on it. Thanks in advance

SCJP 1.4<br />" Somedays ur the dog...other days ur the water hydrant "
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1090
Hi Vinay
A non-static final member variable has to be intialized at the place it is declared or in a constructor or a nonstatic intializer.
In case of a static final intializer the variable has to be intialized at the place it is declared or in a static intializer.
Hope this thread helps you.
subject: static final vars