Hi,
In the below program, I am expecting compilation error according to JCP book as m is not declared before using it. But the program works fine and gives output. Can anybody explain how this program works.
public class Init
{
private static
String msg(String msg)
{
System.out.println(msg);
System.out.println("Open for all");
return msg;
}
public Init()
{
m=msg("1");
System.out.println("I am near 1");
}
{
m=msg("2");
System.out.println("I am near 2");
}
String m=msg("3");
{
System.out.println("I am near 3");
}
public static void main(String args[])
{
Object obj=new Init();
System.out.println("I am in main1");
}
}