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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 41128
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 - my free Android networking tools app
Andry Dub
Ranch Hand

Joined: Nov 06, 2007
Posts: 43
Thank you. Now it is clear for me
subject: Static initialization
Similar Threads
Value of hexadecimal 0xDeadCafe
static nested class
inner classes
Chapter 5 K&B -Doubt
x++ , ++x