Skip to content
Justice Tech School

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

How many classes can one class extend?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.