It is legal to declare a local variable with the same name as an instance variable; this is called "shadowing". : Method Variable « Java Source And Data Type « SCJP
1.21.4.It is legal to declare a local variable with the same name as an instance variable; this is called "shadowing".
class MainClass{ int count = 9; public void logIn() { int count = 10;
System.out.println("local variable count is " + count);
} public void count() {
System.out.println("instance variable count is " + count);
} public static void main(String[] args) { new MainClass).logIn(); new MainClass().count();
}
}
local variable count is 10
instance variable count is 9