2

I am quite confused about forward referencing in Java especially in the context of the code fragment below.

I know that unlike constructors and other methods, a static initialization block can't reference a static variable before it is defined but then why this static initialization block can; as the code below compiles & runs.

 static {
    rate = 10;
    ++rate;
}

private void method(){age++;}

int age;

static int rate
Bilesh Ganguly
  • 3,792
  • 3
  • 36
  • 58

0 Answers0