构造函数
接下来是构造函数,它应该用递增的方式写
(比如:参数多的写在后面)。
访问类型
("public", "private" 等.) 和 任何 "static", "final" 或 "synchronized" 应该
在一行中,并且方法和参数另写一行,这样可以使方法和参数更易读。
public
CounterSet(int size){
this.size = size;
}
克隆方法
如果这个类是可以被克隆的,那么下一步就是
clone 方法:
public
Object clone() {
try {
CounterSet obj = (CounterSet)super.clone();
obj.packets = (int[])packets.clone();
obj.size = size;
return obj;
}catch(CloneNotSupportedException e) {
throw new InternalError("Unexpected CloneNotSUpportedException: " +
e.getMessage());
}
}
类方法
下面开始写类的方法
:
/**
* Set the packet counters
* (such as when restoring from a database)
*/
protected final
void setArray(int[] r1, int[] r2, int[] r3, int[] r4)
throws IllegalArgumentException
{
//
// Ensure the arrays are of equal size
//
if (r1.length != r2.length || r1.length != r3.length || r1.length != r4.length)
throw new IllegalArgumentException("Arrays must be of the same size");
System.arraycopy(r1, 0, r3, 0, r1.length);
System.arraycopy(r2, 0, r4, 0, r1.length);
}
toString 方法