Skip to Content
Dart📘 Ngôn ngữ DartKế thừa (Inheritance)

Kế thừa (Inheritance) trong Dart

🎯 Mục tiêu: OOP với class inheritance.


💡 extends

class Animal { String name; Animal(this.name); void makeSound() => print("Some sound"); } class Dog extends Animal { Dog(String name) : super(name); @override void makeSound() => print("Woof!"); }

📝 super

class Child extends Parent { Child() : super(); // Gọi parent constructor @override void method() { super.method(); // Gọi parent method // Additional logic } }

✅ Checklist

  • extends để kế thừa
  • super để gọi parent
  • @override khi override

Last updated on