- The following code will compile !
int a=0;
void method1(int a0) {
int a1=0;
{ int a=0;}
for(int a=0;a < 10; a++) {
System.out.println("" + a);
}
for(int a=0;a < 10; a++) {
System.out.println("" + a);
}
}
}
The declaration of the integer in the block of code surrounded by {} and in the 2 for will NOT interfere !
- But if you change the name of the method parameter "a0" to "a" OR the name of the local variable "a1" to "a" the method will not compile anymore ! The compiler will complain that "a" hides a field OR that "a" is already defined !
- Could you notice that in the case you didn't rename "a0" and "a1" that the "int a" in the code will hide the instance variable !
No comments:
Post a Comment