Hi
Go through the comment that i was placed in code
package sample;
class StaticTest
{
static int i;
public static void main(
String args[])
{
//This is the Class Level Variable you can use this Class varible since it is staitc
//if you remove the
word static then it is not working .
for (i = 1; i < 3; i++)
{
System.out.print(i);
}
//here varibale is declared inside the llop and scope of the varible is only for this loop
for (int i = 1; i < 3; i++)
{
System.out.print(i);
}
//Declaration is for the main method
int i;
for (i = 0; i < 2; i++)
{
System.out.print(i);
}
//This will print the 3 because in first loop we incremeted the value of i up to 3 and printed upto 2
System.out.print(StaticTest.i);
}
}