Use static block when there is s a requirement to execute block of code when the class is loaded but before instantiating the class. If you write static block of code inside method then you must have instance of class to execute that method and the whole purpose of static initialization block is fail. Hence it will not allowed.
Joined: Sep 12, 2009
Oooops .....We have to follow the rules mentioned JAVA language designers.
Joined: Jul 16, 2010
okay ,the problem is resolved .Thanks for the solution.