Dart Inheritance
Use extends to inherit from one class, @override to replace a method and super to reach the parent.
Example
class Animal { String speak() => "..."; }
class Dog extends Animal { @override String speak() => "Woof"; }
class Cat extends Animal { @override String speak() => "Meow"; }
void main() {
for (var a in [Dog(), Cat()]) print(a.speak());
}Exercise
Inherit.
class Dog Animal
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.