Shadowed variable is an object reference : Method Variable « Java Source And Data Type « SCJP






class Bar {
    int barNum = 28;
  }
  class MainClass {
    Bar myBar = new Bar();
    void changeIt(Bar myBar) {
      myBar.barNum = 99;
      System.out.println("myBar.barNum in changeIt is " + myBar.barNum);
      myBar = new Bar();
      myBar.barNum = 420;
      System.out.println("myBar.barNum in changeIt is now " + myBar.barNum);
    }
    public static void main (String [] args) {
      MainClass f = new MainClass();
      System.out.println("f.myBar.barNum is " + f.myBar.barNum);
      f.changeIt(f.myBar);
      System.out.println("f.myBar.barNum after changeIt is "
                         + f.myBar.barNum);
    }
  }








1.21.Method Variable
1.21.1.Local (Automatic/Stack/Method) Variables
1.21.2.local variables can be marked final.
1.21.3.Local variable has its scope limited to the method who declares it
1.21.4.It is legal to declare a local variable with the same name as an instance variable; this is called "shadowing".
1.21.5.Attempt to use a loop variable outside the code block of the loop.
1.21.6.Local Object References
1.21.7.Shadow an instance variable by declaring a local variable of the same name directly or as part of an argument
1.21.8.Shadowed variable is an object reference