Modifying instance variables from within methods is:
- prescribed by the java language specification, and
- pretty much necessary: that's how object-oriented programming works.
(I mean, if you could not modify an instance variable from within a method, then where would you modify it from?)
If you want a particular instance variable to not be modifiable from within methods, then you must mark it with the final keyword, like this: final int a; --you will still be able to initialize it from the constructor.
Declaring a local variable with the same name as an instance variable is perfectly valid java; however, it is not advised, and that's why you can usually configure your IDE to issue a warning when you do that. Actually, if your IDE is not giving you a warning, then this may mean that you are not compiling with enough warnings enabled. Always enable as many warnings as you can.
this.a;ora;. If you're inside the methodorange()and calla, you'll get the method variable. If you usethis.a, you'll get the class variable. Elsewhere, callingawill get the class variablea(from the instance) inorange. I've updated your question to make this more clear.