Can fields of the class and arguments of the method interfere?

Posted by Roman on Stack Overflow See other posts from Stack Overflow or by Roman
Published on 2010-03-14T14:58:23Z Indexed on 2010/03/14 15:05 UTC
Read the original article Hit count: 226

Filed under:
|
|
|
|

I have a class with a fields called "a". In the class I have a method and in the list of arguments of this method I also have "a". So, which "a" I will see inside of the method? Will it be the field or it will be the argument of the method?

public class myClass {
   private String a;
   // Method which sets the value of the field "a".
   public void setA(String a) {
     a = a;
   }
}

By the way, there is a similar situation. A method has some local (for method) variables whose names coincide with the names of the fields. What will the "see" the method if I refer to such a method-local variable inside the method (the field or the local variable)?

© Stack Overflow or respective owner

Related posts about java

Related posts about visibility