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 的方法。
That's why the Vehicle class, and its subclasses, have either private or protected fields, and public setter and getter methods to provide access.
这也正是Vehicle类及其子类都具有 private或者protected属性,而用publicsetter和getter方法来访问属性的原因。
This class contains three protected attributes and six methods, as shown in Listing 1.
此类包含三个受保护的属性和6个方法,如清单1所示。
The actual class that represents an .aspx page in action is an instance of a class that derives from Page; hence, it can call into protected methods.
真正代表一个 .aspx活动页面的类是从Page派生的一个类的实例;因此,它能够调入受保护的方法。
The actual class that represents an .aspx page in action is an instance of a class that derives from Page; hence, it can call into protected methods.
真正代表一个 .aspx活动页面的类是从Page派生的一个类的实例;因此,它能够调入受保护的方法。
应用推荐