Variable Assignment Having No Effect
Posted: Thu Feb 21, 2013 3:30 pm
Hi,
For below code
public class Test_Assignment {
static int x;
public static void main(String[] args) {
int x = 10;
x = x;
System.out.println(x);
}
}
The code prints 10. Why the assignment x(local variable) = x(static variable initialized with 0) has no effect.
For below code
public class Test_Assignment {
static int x;
public static void main(String[] args) {
int x = 10;
x = x;
System.out.println(x);
}
}
The code prints 10. Why the assignment x(local variable) = x(static variable initialized with 0) has no effect.