class TestOverride {

    public static void main(String[] args) {
        System.out.println("Create a Super object");
        Super sp = new Super();
        System.out.println("\nCreate a Sub object");
        Sub   sb = new Sub();
        System.out.println();
        sp.test();
        sb.test();
        
        sp.staticTest();
        sb.staticTest();

    }
}

class Super {
    Super() {
        System.out.println("In Super constructor");
        test();
    }    

    static void staticTest() {
        System.out.println("In Super.staticTest()");
    }
    
    void test() {
        System.out.println("In Super.test()");
    }
}

class Sub extends Super {

    Sub() {
        // Super class constructor is automatically
        // called before subclass ctor is executed
        // whenever a new instance is created
        System.out.println("In Sub constructor");
    }

    void test() {           // overrides test() in Super
        System.out.println("In Sub.test()");
    }
    
    /* following won't compile, test() already defined */
    // boolean test() {}
    
    void test(String str) { // overloads test()
        System.out.println("In Sub test(String)");
    }      
    
//    void staticTest() {
//        // won't compile
//        // overridden method is static
//    }

    static void staticTest() {
        // compiles with no problems
        System.out.println("In Sub.staticTest()");
    }
}
