Considering some security issues, I don’t want the subclass inherit the static method from its super class,not even call this method, how can I do this? Please help!
Considering some security issues, I don’t want the subclass inherit the static method from
Share
Static methods are not inherited in the same sense as instance methods are. If you declare a static method as public (or package private) it is accessible whether or not there is a local redeclaration in a child class. The local redeclaration merely means that the child class has to qualify the name of the method; e.g.
If you don’t want the
Childclass to be able to call theParent.foomethod, then you need to declare it asprivate(or maybe package private ifChildandParentare in different packages.)But even then, if the
Childclass has permission to use reflection, then it can easily use that to call aprivatemethod in theParentclass. So unless you are sandboxing your code Java access modifiers are not a security mechanism.