... 公开的类方法(Public Class methods) 受保护的类方法(Protected Class methods) 公开的实例方法(Public Instance methods) ...
基于1个网页-相关网页
When fields are declared protected, there is the possibility that methods in subclasses will directly access them, effectively increasing the coupling within a class hierarchy.
将字段声明为受保护时,子类中的方法就有可能直接访问它们,这样就可能有效地增加类层次结构中的耦合。
This approach makes testing protected methods much easier because the test case class can now extend the class that contains the protected methods.
这种方法使得测试受保护的方法非常容易,因为测试案例类现在可以扩展包含受保护方法的类了。
Sometimes you need to write a subclass (often as an inner class) in order to test protected methods.
有时需要编写一个子类(通常作为内部类)来测试 protected 的方法。
应用推荐