Home Segments Top Top Previous Next

660: Mainline

Instance variables and instance methods in the protected part of a class definition are accessible from instance methods that are defined in the same class, compilation unit, or package. Protected instance variables and methods are also accessible from any subclass of the class in which they are declared, whether or not that subclass is in the same package. They are not, however, generally accessible from other packages:

*------------------------------------------------------------* 
| Everywhere else                                            | 
*------------------------ | ---------------------------------* 
                          | 
                          | 
                          | ^  
                          *-* 
*------------------------------------------------------------* 
| *--------------------------------*   *-------------------* | 
| |                *-------------* |   |                   | | 
| |                |    Same     | |   |                   | | 
| |                |    class    | |   |                   | | 
| |                |      |      | |   |                   | | 
| | Rest of the    |      v      | |   | Other compilation | | 
| | compilation -----> minutes <-------- unit, same package| | 
| | unit           |      ^      | |   |                   | | 
| |                |      |      | |   |                   | | 
| |                *----- | -----* |   |                   | | 
| *---------------------- | -------*   *-------------------* | 
*------------------------ | ---------------------------------* 
                          | 
                          | 
                          | 
*------------------------ | ---------------------------------* 
| *---------------------- | -------------------------------* | 
| |          *----------- | -------*                       | | 
| |          | Subclass in another |                       | | 
| |          | compilation unit in |                       | | 
| |          | another package     |                       | | 
| |          *---------------------*                       | | 
| *--------------------------------------------------------* | 
*------------------------------------------------------------*