File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static initialization" Watch "Static initialization" New topic
Author

Static initialization

Andry Dub
Ranch Hand

Joined: Nov 06, 2007
Posts: 43
Hi! Why i can't access z from method goB2 of B2 class?

public class Broom {
static private int x=8;

static{
int z=2;
}

static class B2{
static int y=9;
void goB2(){
System.out.println(x+" "+y+" "+z);
}
}
}


Java is my love
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
z only exists in the block in which it is declared, in this case the static initializer. As soon as that is exited, z ceases to exist. Maybe you meant to write the following:



Ping & DNS - updated with new look and Ping home screen widget
Andry Dub
Ranch Hand

Joined: Nov 06, 2007
Posts: 43
Thank you. Now it is clear for me
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static initialization
 
Similar Threads
inner classes
static nested class
Value of hexadecimal 0xDeadCafe
Chapter 5 K&B -Doubt
x++ , ++x