posted 13 years ago
Hello Vinay,
The concept which you are looking for is called as Shadowing. As per JLS it is legal to declare two variables with same name but having different scope (in that i think one scope should always be class level scope).
In your code also you are declaring two variables with same name but having different scopes. First is an int having class level scope and other is an object reference variable having method scope. By doing this you are shadowing you instance variable with your local variable in the method.
Even it is legal to declare two variables of same type but different scopes.
Thanks.