public class B extends P {
  static int sv = 6;
  int v = 7;
     
  public static void sm() {
    System.out.println(
      "B: sm(): sv = " + sv);
  }

  public P m() {
    System.out.println("B: "
      + sv + " X " + v + " = "
      + ANSWER);
    return this;
  }

  public void newMethod() {
    int v=13;

     // To locate the target of a bare reference, like v, check for
     // local variables and method parameters first...
     System.out.println("B: newMethod: local v = "+v);

     // You can skip the local variables and parameters by using this...
     System.out.println("B: newMethod: this.v = "+this.v);

     // You get the parent class's v (or its inherited v) using super.v... 
     System.out.println("B: newMethod: super.v = "+super.v);

     System.out.println("B: newMethod: calling this.m()");
     this.m();  // Just use m(), for Pete's (your TA's) sake....
     // But the point of this example is to illustrate that 
     // 'this' does not change the way methods are looked up, it
     // works like a standard reference of type B to the current object.
     // That is, we still get the bottom-most m() in this object.

     System.out.println("B: newMethod: calling super.m()");
     super.m();
     // We START looking for m() in the parent class P of the current object.
     // This avoids the bottom-most m() and, in this case, invokes the m()
     // define in the parent class P for the current object.
     // If there wasn't an m() there, it would look in the parent's
     // superclass, and so on up the class heirarchy, until a matching
     // method was found.  Using "super." avoids the dynamic method
     // look-up step (i.e. we don't find the over-riding method.
    
     // What do you expect from this?  It is in poor style:
     super.sm();

     System.out.println();

     // Finally, to access P's newMethod, we must use super here (Why?):
     System.out.println(
        "B: newMethod: calling super.newMethod() (no pun intended)");
     super.newMethod();
    
     System.out.println("B: newMethod is done.\n");
  }
}
