接口使用的注意事項:
- 接口方法不能用public abstract等修飾。接口內不能有字段變量,構造函數。
- 接口內可以定義屬性(有get和set的方法)。如string color { get ; set ; }這種。
- 實現接口時,必須和接口的格式一致。
- 必須實現接口的所有方法。
- 接口使用 interface 關鍵字聲明,它與類的聲明類似。接口聲明默認是 public 的
例:public interface PaintCost
{
int getCost(int area);
}
接口使用的注意事項:
例:public interface PaintCost
{
int getCost(int area);
}
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。