13.4.6
Access to Members and Constructors
BINARY COMPATIBILITY
class Super extends Hyper {
void hello() { System.out.println("hello from Super"); }
}
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. (A flaw in some early versions of Java caused them to print:
hello from Hyper
incorrectly.)
13.4.6   Access to Members and Constructors
Changing the declared access of a member or constructor to permit less access
may break compatibility with pre existing binaries, causing a linkage error to be
thrown when these binaries are resolved. Less access is permitted if the access
modifier is changed from default access to
private
 access; from
protected
access to default or
private
 access; or from
public
 access to
protected
,
default, or
private
 access. Changing a member or constructor to permit less
access is therefore not recommended for widely distributed classes.
Perhaps surprisingly, Java is defined so that changing a member or constructor
to be more accessible does not cause a linkage error when a subclass (already)
defines a method to have less access. So, for example, if the package
points
defines the class
Point
:
package points;
public class Point {
public int x, y;
protected void print() {
System.out.println("(" + x + "," + y + ")");
}
}
used by the
Test
 program:
class Test extends points.Point {
protected void print() { System.out.println("Test"); }
public static void main(String[] args) {
Test t = new Test();
t.print();
248






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

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