Once the subclass-outside-the-package inherits the protected member, that member (as inherited by the subclass) becomes private to any code outside the subclass, with the exception of subclass'es of the subclass . (quoted from SCJP certification by K&B)
What this means is as follows;
in your code in package2 there is a file named ClassC that is inheriting from Class A in package 1. no problems there
However in the same class you also have another classB that is inheriting from class A but here lies the fun part now;
In ClassC main method you are creating an instance of another class B and trying to invoke the display method, this will not work? Why, because as stated above, "Once the subclass-outside-the-package inherits the protected member, that member (as inherited by the subclass) becomes private to any code outside the subclass". From this we can infer that if Class B was declared in a separate file inheriting Class A with the main method the code
would have compiled and executed BUT if you try creating an instance of Class B in Class C and want to invoke the inherited method it will not compile as this inherited protected method for Class B has now become private for Class C.
Please take a look at the following exception now;
I hope this helps in clarifying your doubts