Can I create a package of my own that has the same name as a predefined package
in Java, such as java.lang?
If so, what would the results be? Wouldn’t that enable me to access that package’s protected members?
If not, what prevents me from doing so?
No –
java.langis prohibited. The security manager doesn’t allow “custom” classes in thejava.langpackage and there is no way telling him to accept them.You’re right – own classes declared in the
java.langnamespace would allow you to useprotectedmethods and members of classes in that package, and this is definitly not wanted.This compiles fine – but – try to execute it 😉