/**
 * This program demonstrates that instance method names are resolved
 * at runtime using the runtime type of the object, whereas instance
 * field names are resolved at compile time using the static type
 * of the expression.
 *
 * Inside the method f, the static type of x is Foo, and this is the
 * information used to access x.a; whereas when f is called with an
 * object of type Bar, this is the information used to determine
 * which b() method to dispatch.
 */

public class ShadowTest {
   public static void main(String[] args) {
      f(new Bar());
   }  
   static void f(Foo x) {
      System.out.println(x.a);
      System.out.println(x.b());
   } 
}

class Foo {
   String a = "Foo";
   String b() { return "Foo"; }
}

class Bar extends Foo {
   String a = "Bar";
   String b() { return "Bar"; }
}
