Java Reference
In-Depth Information
The package contract, defining the functionality available within
the package to effect cooperation between package types.
All of these contracts require careful consideration and design.
18.3.1. Accessibility and Overriding Methods
A method can be overridden in a subclass only if the method is access-
ible in the superclass. If the method is not accessible in the superclass
then the method in the subclass does not override the method in the
superclass even if it has the same signature. When a method is invoked
at runtime the system has to consider the accessibility of the method
when deciding which implementation of the method to run.
The following contrived example should make this clearer. Suppose we
have a class AbstractBase declared in package P1 :
package P1;
public abstract class AbstractBase {
private void pri() { print("AbstractBase.pri()"); }
void pac() { print("AbstractBase.pac()"); }
protected void pro() { print("AbstractBase.pro()"); }
public void pub() { print("AbstractBase.pub()"); }
public final void show() {
pri();
pac();
pro();
pub();
}
}
We have four methods, each with a different access modifier, each of
which simply identifies itself. The method show invokes each of these
 
Search WWH ::




Custom Search