Hi,
I am trying to understand Life time of a variable by writing a below program. But unable to compile it as it is throwing some error. please go through below for code snippet and error as follows,
// Understanding Lifetime of a variable. class LifeTime { public static void main(String args[]) { int x; for(x = 0; x <3 ; x++) { int y = -1; // y is initialized each time block is entered System.out.Println("y is: " + y); // this always prints -1 y = 100; System.out.println("y is now: " + y); } } }
I would appreciate your help on fixing this error.
Please refer to the print screen attached 'LifeTime.jpeg' to this thread to know more about error.
Thanks in advance,
Java Beginner