The Artima Developer Community
Sponsored Link

Java Answers Forum
static declaration

1 reply on 1 page. Most recent reply: Aug 3, 2002 9:09 PM by Dan Chisholm

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Nihar Ranjan Pattanaik

Posts: 10
Nickname: nihar
Registered: May, 2002

static declaration Posted: Aug 2, 2002 11:06 PM
Reply to this message Reply
Advertisement
Is it possible to explicitly declare a variable as static inside the static block .If not then why ?


Dan Chisholm

Posts: 11
Nickname: dchisholm
Registered: Jul, 2002

Re: static declaration Posted: Aug 3, 2002 9:09 PM
Reply to this message Reply
Any variable declared within a block is a local variable and can not be declared static.

A static field is also called a class variable and there is only one instance of a class variable regardless of the number of instances of the class. In contrast, multiple threads may execute a block of code simultaneously so multiple copies of a local variable may exist at any point in time. For that reason, the definitions of local variables and static variables are not compatible. Of course, only the JVM calls the static initializer, so the multiple thread problem does not exist in that case.

The C programming language allows a local variable to be declared static so that it behaves like a class variable with a scope that is limited to the code block in which it is declared. Java does not provide that feature.

Flat View: This topic has 1 reply on 1 page
Topic: Applet problem !!! Previous Topic   Next Topic Topic: exception handling

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use