[OSAM]DART言語ベース(13)Class[#5]Class Static Keyword,super Withis


> Static


static:静的メンバーを宣言するキーワード
=>すべてのインスタンスを作成するときに、同じ値のメンバーを入力します.
  • 宣言:静的タイプ変数名
  • 値はメイン関数、classに変更されます.静的変数=値
  • class Employee {
      static String building;
      String name;
    
      Employee(String name) : this.name = name;
      void printInfo() {
        print("저는 ${this.name}이고 ${building}에서 일합니다."); 
        
        //this.building x => 값이 할당 x
      
      }
    }
    void main() {
      Employee a = new Employee('a');
      Employee.building = "아파트";
      a.printInfo();
    }
    

    >super with this


    子は
  • の親属性を完全に継承します.
    => super.name = this.name same
  • 親クラスの属性を子クラスで同じ名前で上書きすると、
    => super.name(親)!=this.name(子)
  • class Employee {
      final String building;
      final String name;
    
      Employee(String building, String name)
          : this.building = building,
            this.name = name;
    }
    
    class Engineer extends Employee {
      String name;
      Engineer(String name, String building) : super(building, name);
      void thisprintInfo() {
        print("저는 ${this.building}에서 일하는 ${this.name}입니다.");
      }
    
      void superprintInfo() {
        print("저는 ${super.building}에서 일하는 ${super.name}입니다");
      }
    }
    
    void main() {
      Engineer e = new Engineer("류희재","아파트");
      e.superprintInfo();
      e.thisprintInfo();
    }
    결과값
    저는 아파트에서 일하는 류희재입니다
    저는 아파트에서 일하는 null입니다.