Question: Using protected. If a method or instance variable is modified by protected (rather than public or private), then it can be accessed by name inside
Using protected.
If a method or instance variable is modified by protected (rather than public or private), then it can be accessed by name inside its own class definition, by name inside any class derived from it, and by name in the definition of any class in the same package. I'm trying to figure out how the bold part is done. Even thouigh I made a variable protected in one class, I couldn't use it in a seperate class in the same pacjage.
1)According to your book, all classes defined within a directory that are not explicitly assigned a package are assigned to a default package. Prove this!
Hint: declared a couple of classes and make the instance variables protected. Can you access instance variables outside of the class definition ?
2) Within an Eclipse workspace (directory) , create two different packages (PackageOne and PackageTwo). Demonstrate that protected access does not go across packages. Again, protected instance variables will help here.
I tried to prove number 1 by using the bold part, but having trouble.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
