File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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;

int z=2;

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

Java is my love
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
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:

Andry Dub
Ranch Hand

Joined: Nov 06, 2007
Posts: 43
Thank you. Now it is clear for me
I agree. Here's the link:
subject: Static initialization
It's not a secret anymore!