TopFallingObject exampleProtected

Protected

You may have noticed that our instance variables in FallingObject, and now our hitBottom method, are declared as protected. The instance variables and the method hitBottom should not be public, because we do not want outside objects to see our instance variables or to be able to call hitBottom. However, if we declare them as private, then subclasses cannot see the variables to use them, nor could the hitBottom method be overridden.

For those of you who go on to CS 136, you will make extensive use of the protected access specifier.

To summarize the three types of protection we have seen:

There is a fourth protection provided by Java, the "default" protection, that is what you get if you don't specify any of the three above. We will not discuss default protection in this class.


TopFallingObject exampleProtected