0

The code likes below:

abstract class BB {
  BB() {
    print('BB Constructor');
    init();
  }
  init() {
    print('BB init');
  }
}

mixin GB on BB {
  @override
  init() {
    super.init();
    print('GB init');
  }
}

mixin PB on BB {
  @override
  init() {
    super.init();
    print('PB init');
  }
}

class WFB extends BB with GB,PB {}

It will print:

BB Constructor
BB init
GB init
PB init

I know the PB's init method will cover GB's init method. So why it invokes GB's init method.

dowZhang
  • 470
  • 1
  • 3
  • 18
  • I presume that you're asking why instantiating `WFB` would print that output. See https://stackoverflow.com/a/45903671/: `class WFB extends BB with GB, PB` creates an internal class hierarchy with `BB`, `GB`, and `PB`. (Your output is a little confusing because you put the `print` statements *after* calling `super.init()`, so your output is in the opposite order from when the `init()` methods are called.) – jamesdlin Mar 08 '23 at 06:30
  • So what is the structure of this internal class?@jamesdlin – dowZhang Mar 08 '23 at 13:32
  • WFB derives from a $PB which derives from $GB which derives from BB, where $PB and $GB are synthesized classes generated from PB and GB respectively. This is explained by the linked answer. – jamesdlin Mar 08 '23 at 15:40

0 Answers0