[CODE=Java]public class mainclass1 {
public static void main(String[] args) {
for(int i= 0;i<1;i++)
a obj = new a();
}
}
class a{
}
[/CODE]
In the above program if you try to create an object with in "for" loop then you will get an error stating "not a statement "
ex:
[CODE=Java]for(int i= 0;i<1;i++)
a obj = new a();[/CODE]
but if you try to create an object with brackets then it will create without an error
ex:
[CODE=Java]for(int i= 0;i<1;i++) {
a obj = new a();
}[/CODE]
why is it so , and whats the problem , Please explain it.
Thanks in advance.
public static void main(String[] args) {
for(int i= 0;i<1;i++)
a obj = new a();
}
}
class a{
}
[/CODE]
In the above program if you try to create an object with in "for" loop then you will get an error stating "not a statement "
ex:
[CODE=Java]for(int i= 0;i<1;i++)
a obj = new a();[/CODE]
but if you try to create an object with brackets then it will create without an error
ex:
[CODE=Java]for(int i= 0;i<1;i++) {
a obj = new a();
}[/CODE]
why is it so , and whats the problem , Please explain it.
Thanks in advance.
Comment