Extend How inheritance works in in Dart

This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below.
Get Unlimited PRO Access

OR


*Enrollment provides full access to this course (and updates) for life.

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.');
  }
}

Q&A Chat