Dart

[Dart] Class - Static

unsungIT 2021. 5. 27. 20:51
void main() {
  // Method overriding
  Student.schoolName = 'Korea';
  Student kim = new Student(1, 'kim');
  kim.who();
}

// 학생, 학교이름, 학년, 학생이름
class Student {
  static String? schoolName;
  int grade;
  String name;

  Student(this.grade, this.name);

  void who() {
    print('I am $name, grade is $grade, school name is $schoolName');
  }
}

--------------------------------------------[result]

I am kim, grade is 1, school name is Korea