Java Reference
In-Depth Information
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
Click here to view code image
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();
}
Search WWH ::




Custom Search