Guys this is simple trying to do some working of access levels of member variables and method in regard to parent and child references.
Everything is clear except for protected access we cannot have a parent reference access the member variables if it is in another package why?
This does not work compile error due to parent reference
Protected members can be accessed from anywhere within the same package. That's why your second example compiles. Protected members can only be accessed by subclasses in different packages if they are their own method. That means an instance of Child can methodX2(), but only using itself (or other instances of Child) as the reference. Using a Parent reference is not allowed.
That shows a class of you.! I figured that one out later. But thats exactly why it is not compiling. I thaught I would leave it as a lesson for other developers on this hidden subject
Regards
Mohamed
SCJP, SCWCD, SCBCD, SCEA 5
Don't get me started about those stupid light bulbs.