// INHERIT6
// See $show$ below. This method is accessed from
// the actual object, which means that even though the
// code for $show$ is written in the superclass, 
// you have to pretend it is written in the subclass!

// To explain the behavior, remember the rules for creating
// objects: all instance variables are set to defaults,
// the constructor of the superclass invokes, the instance
// variables are initialized, and the constructor finishes
// executing. All of this occurs before the subclass constructor
// executes! So, $z$ has a default value of zero when the 
// first $show$ method is invoked.

class A {
    public int x;
    public int y = 10;
    public A(int x) { 
	this.x = x;
	System.out.println("x from the A constr: "+x);
	show();
    }
    public void show() {System.out.println("(A): "+x);}
}
class B extends A { 
    public int z=100;
    public B(int x) {
	super(x-1);
	this.x=x;
	show();
    }
    public void show() {
	System.out.println("(B): "+(x+y+z));}
}

public class inherit6 {
    public static void main(String[] args){
	
	System.out.println("\nTest 1:");
	B v1 = new B(2);
	System.out.println("v1 uses "+v1.getClass());
	System.out.println("accessing x: "+v1.x); 
	v1.show();

	System.out.println("\nTest 2:");
	A v2 = new B(2);
	System.out.println("v2 uses "+v2.getClass());
	System.out.println("accessing x: "+v2.x); 
	v2.show();
    }
}

/* sample output:
Test 1:                  Test 2:                
x from the A constr: 1	 x from the A constr: 1 
(B): 11			 (B): 11                 
(B): 112		 (B): 112                 
v1 uses class B		 v2 uses class B        
accessing x: 2		 accessing x: 2         
(B): 112		 (B): 112                 
*/







