Hi Ritu ,
Okay the explaination is like this..
In the first case, where you have declared int i,
YOu have declared int i at class level, which makes it instance variable and int i declared inside the method as a parameter becoems a local variable which shadows the class level variable.
So in the method if u access i, it will be accessing the local variable i and not the one declared at class level, to access instance variable i, u 'll use 'this' operator.
In the second example, it is not the same case as expalined above.
okay, shadowing happens in cases of parameter passing and inheritence (only when u extend classes).
so ur first example is case of shadowing.
and ut second example gives compilation error as there is no shadowing involved and it breaks the rules of variable declaration where my earlier explaination gets valid.
i know u'r bit confused. just read a bit more about shadowing and variable declaration.
As i don't log on to javranch often, if u have any problems or clarifications , u can contact me at email@example.com