-
private or protected5
以前我写class 除了公有的方法就是私有的方法。只要不是给别人用的都写成私有的
现在为了测试方便习惯把testCase跟测试对象放在一个包里,然后把方法都写成protected方便测试。
这种方法好吗,什么时候应该用私有方法,什么时候用protected方法呢?2008年7月23日 07:52
4个答案 按时间排序 按投票排序
-
采纳的答案
你的需求不应该用protected。
protected只用于子类继承需要override的情况。
你的需求用默认的包访问权限即可。请记住java有4种可见性控制,private、public、protected以及什么都不加时的包访问权限。2008年7月24日 11:24
-
建议测试代码放到同一个包中,但最好放在不同的文件夹中。
例如在eclipse中,代码放到src中, 测试代码放到test中,包名可以相同.
如:com.abc.blabla
楼上说的对,protected是给之类继承时用的,如果不想给之类使用就用private。public的就不用说了。2008年7月24日 11:04
-
如果一个类是需要被继承的,而且他的方法,子类又用得到,就用protected
话说回来,要理解这个问题,需要了解面向对象中,对象之间的关系
一般来说,如果对象之间是依赖关系,用public
而聚合关系一般都用protected的
如果这个方法不想和外界打交道就是private
总的来说,private是自己用的,protected是给子类继承用的2008年7月23日 10:10
相关推荐
Files are being decrypted even in a case when the system is not bootable and so you cannot log on, and/or some encryption keys (private or master) have been tampered. Besides, decryption is possible ...
* Whether to use AKSpeak messages or not. */ protected boolean useSpeak; /** * Construct a SEU Agent. */ protected SEUAgent() { importantmessage =new ImportantMessage(); smartchoose = new ...
These objects are instances of classes, which act as blueprints or templates. A class defines the properties and actions that its objects will have. For instance, in designing a car, the class might ...
For example final classes and methods cannot be used, private methods sometimes need to be protected or unnecessarily moved to a collaborator, static methods should be avoided completely and so on ...
In the case of symmetric key algorithms, the single key must be kept secret from everyone and everything not specifically authorized to access the information being protected. In asymmetric key ...
Occasionally, private members are listed because they override a public or protected member in the base class. See the class header files for a complete listing of class members. Some C-language ...
* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding ...
private,protected,internal,public 访问权限 private:只能在类本身内部访问,按惯例,命名私有成员时以下划线“_”开首;protected:可以由类本身或不论什么子类访问。但这是以实例为基础的。换言之,类实例可以...
protected Implementor implementor; public void SetImplementor(Implementor imp) { implementor = imp; } public abstract void Operation(); } public interface Implementor { void ...
It can test all methods including public protected, as well as private Automation regression is also build in framework None java coding jobs for test case development You can test you cases in every ...
protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); // Calculate our view width mGalleryWidth = right - ...
change size or color ball.setRadius(ball.getRadius() * 1.5f); // Increase size ball.setColor(Color.RED); // Change color } // Draw the ball canvas.drawCircle(ball.getX(), ball.getY(), ball....
最佳的方法是将析构函数声明为private,而构造函数保持为public。这样可以限制栈对象的生成,同时也允许使用new来产生堆对象。 例如: ```cpp class NoStackObject{ protected: ~NoStackObject(){}; public: void...
Data Guard Pro is a powerful and new computer security program that lets you create protected storage regions called Privacy Blocks in your local hard disk partitions where you can store your private ...
private static final String IMPLEMENTOR = "implementor"; public EndpointDefinitionParser() { setBeanClass(SpringEndpointImpl.class); } protected String getSuffix() { return ".jaxws-endpoint...
Dim handle As IntPtr = CreateFile(devicePath, GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero) If handle <> INVALID_HANDLE_VALUE Then ...
- **可见性修饰符**:Kotlin 支持 public、private、protected 和 internal 四种可见性级别。 - **扩展**:Kotlin 支持为现有的类添加新的功能,无需继承或封装。 - **数据类**:Kotlin 的数据类提供了一种方便的...
{ private static byte[] Key64 = { 42, 16, 93, 156, 78, 4, 218, 32 }; private static byte[] IV64 = { 55, 103, 246, 79, 36, 99, 167, 3 }; protected void Page_Load(object sender, EventArgs e) { } ...
in CONFIG SYS or it can load later in AUTOEXEC BAT or by user command DOS can copy critical programs and data to the RAMdisk where they will be read or written at memory speed If loaded after ...
经典JS 这是一个旨在为ES6类提供完全特权成员支持的库。 这意味着您将充分使用当使用C#,Java和C ++等语言时可能已经习惯的访问说明。 您将获得所有这些,而不会...const { STATIC , PRIVATE , PROTECTED , PUBLIC ,