This works fine when using one ClassLoader. However if MyClass is loaded in the parent classloader and SubClass in the child classloader (of the parent), the child classloader complains with a VerifyError: Bad access to protected data
As written, SubClass is allowed to call MyClass.myMethod() in doSomething() only because the two classes are in the same package. The rules for "protected" state that you can call a protected method only on a reference that is at least the same type as the calling class -- i.e., SubClass could call SubClass.myMethod(), or myMethod() on a "SubSubClass" class, but not on an instance of MyClass or on any other class. The only reason the access is allowed is because all classes in a package can access each other's protected methods.
Once two classes are loaded by two different ClassLoaders, they're not technically in the same package anymore; see VM Specification. Therefore, this "back door" disappears, and you're bound by the standard definition of "protected" across packages.
The long and short of it is that a method like "doSomething()" must be in "MyClass" or it's not going to work. [ April 03, 2006: Message edited by: Ernest Friedman-Hill ]