Shadowing did the trick Kshitij. This feature of
Java is called shadowing. You can use the same name for an instance variable and a method parameters. If you take a look at the method
Whatever you pass as a parameter to the method go() is named x and it has nothing to do with the instance variable x. The scope of the method parameter x is only limited to that method. This will throw only an error only if you try to do something like this
So don't get confused with the instance variable x and the method parameter x. The same rule applies for the second piece of code also.