Can somebody give an eg for the following: 1.Forward references to variables gives compiler error. 2.Instance initializer(s) gets executed ONLY IF the objects are constructed.
Paul Anilprem
Enthuware Software Support
Ranch Hand
Joined: Sep 23, 2000
Posts: 2912
posted
0
public class TestClass {  static{ System.out.println(" in static block"); }  { System.out.println(" in non static block"); }  public static void main(String args[])  {   // i = 10; //will give compile time error.   // int i;   //new TestClass(); //"in non-static block" will not be printed.  } } HTH, Paul.
1.Forward references to variables gives compiler error. Paul gave an example. To be nit-picky and confuse you more, I'll give an example when they do not give compiler error.
this code compiles because static vars are initizlized before instance vars, so forward reference instanceVar = staticVar is legal.