class TestHiding {

    public static void main(String[] args) {
    
        SuperA x = new SuperA();
        SubA   y = new SubA();
        
        System.out.println("SuperA x, y = " + x.x + ", " + x.y);
        System.out.println("SubA   x, y = " + y.x + ", " + y.y); 
        
        x.method1();
        y.method1();
        x.method2();
        y.method2();
        
        // access hidden method1 in SuperA
        ((SuperA)y).method2();
    }
}

class SuperA {
    int x = 10;
    static int y = 15;
    
    void method1() {
        System.out.println("SuperA method1");
    }
    
    static void method2() {
        System.out.println("SuperA static method2");
    }
    
}

class SubA extends SuperA {
    int x = 20;         // hides x in superclass
    int y = 30;         // hides y in superclass
    
    // if 'static' is added to the declaration
    // a compile-error occurs; cannot hide an instance
    // method in the superclass with a static method in
    // a subclass
    void method1() {
        System.out.println("SubA method1"); // overrides method1 in SuperA
    }
    
    // if 'static' is removed from the declaration
    // a compile-error occurs
    static void method2() {
        System.out.println("SubA static method2");
    }    
}
