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 EE Developer (OCPJP/OCPJWCD)