A
asit
yesterday I read ab Non Static block.
I tried the following code
public class NonSta
{
int i;
NonSta()
{
System.out.println("Constructor");
i++;
System.out.println(i);
}
{
System.out.println("Non Static Block");
i += 10;
System.out.println(i);
add(100);
new NonSta();
}
void add(int k)
{
System.out.println("Add Block");
i += k;
System.out.println(i);
}
public static void main(String args[])
{
NonSta n = new NonSta();
}
}
I found that it becomes an infinite loop if the non static block
contains a call to constructor.
Does it logically imply "Non static block can't contain a
constructor".
Plz reply me !!!
I tried the following code
public class NonSta
{
int i;
NonSta()
{
System.out.println("Constructor");
i++;
System.out.println(i);
}
{
System.out.println("Non Static Block");
i += 10;
System.out.println(i);
add(100);
new NonSta();
}
void add(int k)
{
System.out.println("Add Block");
i += k;
System.out.println(i);
}
public static void main(String args[])
{
NonSta n = new NonSta();
}
}
I found that it becomes an infinite loop if the non static block
contains a call to constructor.
Does it logically imply "Non static block can't contain a
constructor".
Plz reply me !!!