JVM Knowledge

No incompatibility with pre-existing binaries is caused by adding an instance (respectively static) member that has the same name and accessibility (for fields), or same name and accessibility and signature and return type (for methods), as an instance (respectively static) member of a superclass or subclass. No error occurs even if the set of classes being linked would encounter a compile-time error.

Deleting a class member or constructor that is not declared private may cause a linkage error if the member or constructor is used by a pre-existing binary.

Example 13.4.6-1. Changing A Class Body

class Hyper {
    void hello() { System.out.println("hello from Hyper"); }
}
class Super extends Hyper {
    void hello() { System.out.println("hello from Super"); }
}
class Test {
    public static void main(String[] args) {
        new Super().hello();
    }
}

This program produces the output:

hello from Super

Suppose that a new version of class Super is produced:

class Super extends Hyper {}

Then, recompiling Super and executing this new binary with the original binaries for Test and Hyper produces the output:

hello from Hyper

as expected.

The super keyword can be used to access a method declared in a superclass, bypassing any methods declared in the current class. The expression super.Identifier is resolved, at compile time, to a method m in the superclass S. If the method m is an instance method, then the method which is invoked at run time is the method with the same signature as m that is a member of the direct superclass of the class containing the expression involving super.

Example 13.4.6-2. Changing A Superclass

class Hyper {
    void hello() { System.out.println("hello from Hyper"); }
}
class Super extends Hyper { }
class Test extends Super {
    public static void main(String[] args) {
        new Test().hello();
    }
    void hello() {
        super.hello();
    }
}

This program produces the output:

hello from Hyper

Suppose that a new version of class Super is produced:

class Super extends Hyper {
    void hello() { System.out.println("hello from Super"); }
}

Then, if Super and Hyper are recompiled but not Test, then running the new binaries with the existing binary of Test produces the output:

hello from Super

as you might expect.