Local variable scope and for loop
I just have started to learn Java. I have some dummy question. I don't
really get why in this situation:
int j = 5;
for (int j = 0; j < 10; j++) {
// do sth
}
my compiler says : the variable j is already defined in the scope.
Why this second j is a problem ? I thought that it should simply shadow
the first one.
No comments:
Post a Comment