This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
In the third code snippet I think you mean to import test2.* rather that test1.*. Anyway, the protected access modifier respects inheritance.
Note that in the following code snippets a compile time error occurs stating that The field Test1.val is not visible.
In the first snippet below the Test4 class is a "neighbour" of the Test3 class and in the second snippet the Test4 class is in a completely different package and therefore cannot access the protected variable.
Alex Theedom - Senior Java Developer (OCPJP/OCPJWCD)