Thomas Hauck wrote:I am going to list the steps for accessing a protected field in a class that has been imported.
I don't like this phrasing. There is no such thing in
Java as "importing a class" (as in some kind of copy & paste the contents of one class in another one). An import statement just allows you to use the class name (instead of it's fully qualified name), so you'll be saving lots of key strokes and your code has less clutter which makes it easier to read.
Thomas Hauck wrote:Steps involved to access a "protected" member field in a class of a separate package.
This is much better than the previous statement! It's really spot-on
Thomas Hauck wrote:Question: Is there anything else one should know about "protected access "?
Understanding the bits and pieces of "protected" access (and the subtle different with "default" access) is one of the hardest parts of the OCAJP7 certification. As a reminder think of default =
package-private and protected =
package-private + kids. If the subclass is in a different package, then you can only access a protected member from its superclass by inheritance (not using a reference variable).
To illustrate I updated your example a little bit. The
Mammal class isn't changed. I also included unique line indicators, so you can use them to ask questions if needed.
Hope it helps!