• Post Reply Bookmark Topic Watch Topic
  • New Topic

A Query about static variables  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi ,

Please tell me , "Are static variables implicitly final (Constants) "?
 
Rok Štelcer
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
Ravi Kiran V wrote:
Please tell me , "Are static variables implicitly final (Constants) "?

No. You need to define a static var explicitly as final ... only then it becomes a constant.


Regards,
Rok
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much .

Refreshing my core java knowledge
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Manu Ullas
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran V wrote:
Hi ,

Please tell me , "Are static variables implicitly final (Constants) "?


I see that your query has already been answered but you might like to know that static variables, especially static int/float/double/char are initialized to 0 implicitly.

A bit of trivia for you.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

No. You need to define a static var explicitly as final ... only then it becomes a constant.


First of all sorry for reopening this thread .
I am having a query on static variables . My doubt is as static variables are loaded only once that is when the class is loaded by the JVM .How can its value be changed again and again


 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran V wrote:
First of all sorry for reopening this thread .
I am having a query on static variables . My doubt is as static variables are loaded only once that is when the class is loaded by the JVM .How can its value be changed again and again


The static initializer, and initialization of static variables is only executed once (when the class is loaded by the JVM).... but... are there other things that can also change static variables?

Henry
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but... are there other things that can also change static variables?


what do you mean by this ??
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
initialized at loading time and declaring a variable of class level does not prevent it from being reassigned, however final has different meaning, it does not insist on initializing at load, One more property...left to you!
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!