[OSAM]DART言語ベース(13)Class[#5]Class Static Keyword,super Withis
> Static
static:静的メンバーを宣言するキーワード
=>すべてのインスタンスを作成するときに、同じ値のメンバーを入力します.
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입니다.
Reference
この問題について([OSAM]DART言語ベース(13)Class[#5]Class Static Keyword,super Withis), 我々は、より多くの情報をここで見つけました https://velog.io/@hello_hidi/OSAM-DART-언어-기초13-Class-5-Class-Static-Keywordテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol