Originally posted by Ernest Friedman-Hill:
Nope. Only code in SubClass, or a subclass of SubClass, can call that protected method on a SubClass object. Extending MyObject is not enough. That's just how it works.
If you want to make the method available to other random code, then yes, you have to override it to make it a public method, as in your first example.
Ok, I'll live by that rule now. But I don't really understand the reasoning behind it.
Consider Object. It's clone() is protected. Now it is not available to any class in the
Java World unless it redefines this method. While I don't know what's the spirit behind such an implementation, it definitely is not making use of code reuse, you see.