Directory Portals: A Guide to The Quick Start To Flutter

inheritance

Dart inherits a class using the extends keyword.

In particular, constructors cannot be inherited in Dart.

Except for classes where the default constructor is null, the constructor is automatically inherited by subclasses.

If a subclass wants to call the constructor of its parent class, the super keyword can be used.

class NewPoint extends Point{
  NewPoint(x, y):super(x, y);
  NewPoint.newOrigin():super.origin() {print('$x, $y'); }}Copy the code

When newpoint.neworigin () is called, the origin constructor of the parent class is called before the expression inside that constructor is executed.

Where the constructor of the form newpoint.neworigin () is called the named constructor.

implementation

In Dart, you use the implements keyword to inherit a class.

It means that a subclass inherits the PARENT class’s API, but not its implementation.

Unlike Java, Dart can directly inherit from a common class.

// A person. The implicit interface contains greet().
class Person {
  // In the interface, but visible only in this library.
  final _name;

  // Not in the interface, since this is a constructor.
  Person(this._name);

  // In the interface.
  String greet(String who) => 'Hello, $who. I am $_name.';
}

// An implementation of the Person interface.
class Impostor implements Person {
  get _name => ' ';

  String greet(String who) => 'Hi $who. Do you know who I am? ';
}

String greetBob(Person person) => person.greet('Bob');

void main() {
  print(greetBob(Person('Kathy')));
  print(greetBob(Impostor()));
}Copy the code

Directory Portals: A Guide to The Quick Start To Flutter

How can I be found?

Portal:CoorChice homepage

Portal:Lot of CoorChice