👩‍👦 Extend

How inheritance works in in Dart

Superclass

The superclass or parent class contains the behaviors that is shared by all subclasses. The abstract keyword is used to indicate that the class is not meant to be instantiated, but rather to be inherited from.

file_type_dartlang extend.dart
abstract class Dog {
  void walk() {
    print('walking...');
  }
}

Subclass

The subclass can @override the behavior of the superclass.

file_type_dartlang extend.dart
class Pug extends Dog {
  String breed = 'pug';

  @override
  void walk() {
    super.walk();
    print('I am tired. Stopping now.');
  }
}

Questions? Let's chat

Open Discord