.png)
class์ extends๋ผ๋ keyword๋ฅผ ์ฌ์ฉํ์ฌ ๋ถ๋ชจ class๋ฅผ ์์๋ฐ์ ์ ์๋ค.
. ์์์ ๋ถ๋ชจ์ ๋ชจ๋  ํจ์ ๋ฐ ๋ณ์๋ฅผ ์์๋ฐ์ง๋ง ๋ถ๋ชจ๋ ์์์ ์ด๋ ํ ๊ฒ๋ ์์๋ฐ์ง ์๋๋ค.
. ์์์ 2๊ฐ์ ์ด์์ ๋ถ๋ชจ class๋ฅผ ๊ฐ์ง ์ ์๋ค. 
void main() {
  //Inheritance
  Idol seulgi = Idol(name: '์ฌ๊ธฐ', group: '๋ ๋๋ฒจ๋ฒณ');
  seulgi.sayName();
  seulgi.sayGroup();
  
  //๋ถ๋ชจ์ ๊ฒ์ ๋ชจ๋ ์์ ๋ฐ์์ ํจ์๋ฅผ ์ฌ์ฉํ  ์ ์๋ค.
  BoyGroup rm = BoyGroup('rm', 'bts');
  rm.sayName();
  rm.sayGroup();
  
  rm.sayMale();
  
  GirlGroup chorong = GirlGroup('์ด๋กฑ', '์์ดํํฌ');
  chorong.sayFemale();
}
class Idol {
  final String? name;
  final String? group;
  //this๋ ํ์ฌ class๋ฅผ ์๋ฏธํ๋ค.
  Idol({this.name, this.group});
  
  void sayName() {
    print('์  ์ด๋ฆ์ $name์
๋๋ค.');
  }
  
  void sayGroup() {
    print('์ ๋ $group ์์์
๋๋ค.');
  }
}
class BoyGroup extends Idol {
  //super๋ ๋ถ๋ชจ class๋ฅผ ์๋ฏธํ๋ค.
  //๋ถ๋ชจ ํค์๋์ ๋ฌด์ธ๊ฐ๋ฅผ ์ฐ๊ณ  ์ถ์ ๊ฒฝ์ฐ์ super๋ผ๋ keyword๋ฅผ ์ฌ์ฉํ  ์ ์๋ค.
  BoyGroup(String name, String group) : super(name: name, group: group);
  
  void sayMale() {
    print('์ ๋ ๋จ์ ์์ด๋์
๋๋ค.');
  }
}
class GirlGroup extends Idol {
  GirlGroup(String name, String group) : super(name: name, group: group);
  
  void sayFemale() {
    print('์ ๋ ์ฌ์ ์์ด๋์
๋๋ค.');
  }
}
void main() {
  //Method Overriding
  Parent parent = Parent(3);
  Child child = Child(3);
  Child child2 = Child(3);
  
  print(parent.calculate());   // 3 * 3 = 9
  print(child.calculate());    // 3 + 3 = 6
  print(child2.calculate2());  // (3 * 3) + (3 * 3) = 18
}
class Parent {
  final int number;
  Parent(this.number);
  
  //Method๋ผ๊ณ  ๋ถ๋ฅธ๋ค.
  int calculate() {
    return number * number;
  }
}
class Child extends Parent {
  Child(int number): super(number);
  
  //@ : decorator
  @override
  int calculate() {
    return number + number;
  }
  
  int calculate2() {
    int result = super.calculate();
    
    return result + result;
  }
}
์ถ์ฒ:YOUTUBE-์ฝ๋ํฉํ ๋ฆฌ