posted 16 years ago
Hi Dinesh,
I think it might be illegal to put anything but declarations at the top level of a class. If you want that code to run everytime you instantiate an object of the class, you can put the System.out.println("hi"); code between curly braces, and that will convert it into an initialization block that will run everytime you create an instance of the class.
I rethought this, and you can also put initialization blocks, static initialization blocks, and method definitions (but a method definition is a type of declaration.)
[ December 17, 2008: Message edited by: Ruben Soto ]
All code in my posts, unless a source is explicitly mentioned, is my own.