13.4.5
Class Body and Member Declarations
BINARY COMPATIBILITY
Hyper
even though compiling the source for these binaries:
class Hyper { String h = "Hyper"; }
class Super extends Hyper { char h = h ; }
class Test extends Super {
public static void main(String[] args) {
String s = new Test().h;
System.out.println(s);
}
}
would result in a compile time error, because the
h
in the source code for
main
would now be construed as referring to the
char
field declared in
Super
, and a
char
value can't be assigned to a
String
.
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,
even if the member was an instance method that was overriding a superclass
method. This is because, during resolution, the linker looks only in the class that
was identified at compile time. Thus, if the program:
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();
}
}
is compiled and executed, it produces the output:
hello from Super
Suppose that a new version of class
Super
is produced:
class Super extends Hyper { }
If
Super
and
Hyper
are recompiled but not
Test
, then a
NoSuchMethodError
will result at link time, because the method
hello
is no longer declared in class
Super
.
246
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved