I have gone through the protected access modifiers at page 35 of scjp 1.6 written by kathy and bert and i have written a similar code in eclipse an tested it and works not as mentioned in the book .code is as follows .
Vegetable bean is the parent class in the food package is as follows
Receipe is the child class which is in the package snack
The code works perfectly fine and there are no errors .According to the book the compiler MUST give an error at bean.kilo , since i am accessing the protected variable NOT THROUGH INHERITANCE BUT THROUGH REFERENCE .I AM LOST NOW AND KINDLY CAN YOU CLARIFY .
Go back to Chapter one and read on the section "Access Modifiers (Exam Objectives 1.3 and 1.4)" and take a closer look at Figure 1-4 on protected members access through Inheritance you'll understand why.
In your case you access protected member "kilo" through Inheritance so, even you in different package you still able to access "kilo". See Figure 1-4 for more insight.
You don't need to create a new instance of VegetableBean to access "kilo" member since "kilo" is static and you access it through Inheritance.
Hope that clear up your confusion...
"Your life is in your hands, to make of it what you choose."
Seriously Rick? Seriously? You might as well just read this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth