B. 函數、類等的說明。對幾乎每個函數都應有適當的說明,通常加在函數實現之前,在沒有函數實現部分的情況下則加在函數原型前,其內容主要是函數的功能、目的、算法等說明,參數說明、返回值說明等,必要時還要有一些如非凡的軟硬件要求等說明。公用函數、公用類的聲明必須由注解說明其使用方法和設計思路,當然選擇恰當的命名格式能夠幫助你把事情解釋得更清楚。
/** * A class representing a set of packet and byte counters * It is observable to allow it to be watched, but only * reports changes when the current set is complete */
接下來是類定義,包含了在不同的行的 extends 和 implements
public class CounterSet extends Observable implements Cloneable
.Class Fields
接下來是類的成員變量:
/** * Packet counters */
protected int[] packets;
public 的成員變量必須生成文檔(JavaDoc)。proceted、private和 package 定義的成員變量假如名字含義明確的話,可以沒有注釋。
/** * Get the counters * @return an array containing the statistical data. This array has been * freshly allocated and can be modified by the caller. */
public int[] getPackets() { return copyArray(packets, offset); }