my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how to access variables in static ini blocks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how to access variables in static ini blocks" Watch "how to access variables in static ini blocks" New topic
Author

how to access variables in static ini blocks

amal shah
Ranch Hand

Joined: May 05, 2006
Posts: 92
consider the code below:

static
{
int x=5; //1
}
static int x=10; //2
System.out.println(x); //3
now here at line 3 variable at line 2 will be accessed...how can i access variable at line 1 since this variable is local to the the static initialiser block....help appreciated

thanking you
amal shah
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
That variable is in scope only inside the block.
Ivan Rebrov
Ranch Hand

Joined: Jul 09, 2006
Posts: 30


or so




2. There is no way to get local "x" variable from line 1 after the end of this static init block. Because this variable is LOCAL.
[ August 11, 2006: Message edited by: Ivan Rebrov ]

SCJP 5.0 - 95%<br />Preparing for SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to access variables in static ini blocks
 
Similar Threads
static variable
variables in static methods
illegal Forward Reference...
explain the static,constructor concept
primitive value