This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
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
 
Have you checked out Aspose?
 
subject: Static initialization
 
It's not a secret anymore!