System.out.println("Here"); //Does not work.!!!
System.out.println("Here"); //Works. Why ??
public void test()
public static void main(String args)
Simple obj = new Simple() ;
Above given code will not compile,
but it will work just fine if I enclose the line
//4 within initializer block.
A class body may contain declarations of members of the class, that is, fields (�8.3), classes (�8.5), interfaces (�8.5) and methods (�8.4). A class body may also contain instance initializers (�8.6), static initializers (�8.7), and declarations of constructors (�8.8) for the class.
Therefore, if you want to put that expression in your class, it must go in either a method, an instance initializer, a static initializer, or a constructor.
I hope that helps,
not a static block but an instance initializer.
A static block is declared as follows