Skip to content
On this page

다트 언어 배우기8 - 오버라이딩

void main() {
  Tree trees = new Tree(
    'hello',
    100
  );

  print(trees.ageCalc());

  Sonamoo strong = Sonamoo(
    '튼튼이',
    10
  );

  print(strong.ageCalc());
}


class Tree {
   final String name;
   final int age;

   Tree(
     this.name,
     this.age
   );

  int ageCalc() {
    return this.age * 10;
  }
}


class Sonamoo extends Tree {
  Sonamoo(
    String name,
    int age
  ) : super(name,age);

  @override
  int ageCalc() {
    return super.ageCalc() * 120;
  }


}

Video Label