JAVAコーディング

クラス その2

2008年05月05日
interface interfaceA {
  String getVal();
  void setVal(String strVal);
}


public class clsFunction implements interfaceA {
  private String strVal;

  public String getVal() {
    return strVal;
  }

  public void setVal(String strVal) {
    this.strVal = strVal;
  }
}


インターフェイスは複数指定も可能です。implements interfaceA,interfaceB,interfaceC ・・・
クラスを継承するときは、
class B extends superClassA implements interfaceA
と書きます。クラスBはsuperClassAを継承。


クラスを使用するときは
clsFunction function = new clsFunction();
function.setVal(strCode);
strCode = function.getVal;