// INHERIT7b

// rem: methods call vars from class in which methods are written
// when a method is overriden, the subclass version is used

class A {
    public int x = 1;
    public A() { show1(); show2(); }
    public void show1() {System.out.println("show1: from A (x): "+x);}
    public void show2() {System.out.println("show2: from A (x): "+x);}
}

class B extends A {
    public int x = 2;
    public int y = 1;
    public B() { show2(); }
    public void show2() {
	System.out.println("from B (x): "+x);
	System.out.println("from B (y): "+y);
    }
}

public class inherit7b {
    public static void main(String[] args) {
	B b = new B();
	A a = b;
	System.out.println("from main (x): "+b.x);
	System.out.println("from main (x): "+a.x);
	b.show1();
	b.show2();
	a.show1();
	a.show2();

    }
}

/* output:	
show1: from A (x): 1
from B (x): 0
from B (y): 0
from B (x): 2
from B (y): 1
from main (x): 2
from main (x): 1
show1: from A (x): 1
from B (x): 2
from B (y): 1
show1: from A (x): 1
from B (x): 2
from B (y): 1
*/
