Junior — Middle
Does the Dart language support the concept of multiple class inheritance?
sobes.tech AI
Answer from AI
In the Dart language, multiple inheritance of classes is not supported. A class can only inherit from one superclass.
However, Dart provides a mechanism called mixins, which allows adding functionality from multiple sources without using multiple inheritance.
Example of using mixins:
mixin A {
void methodA() => print('A');
}
mixin B {
void methodB() => print('B');
}
class C with A, B {}
void main() {
var c = C();
c.methodA(); // Prints 'A'
c.methodB(); // Prints 'B'
}
Thus, in Dart, mixins are used for code reuse instead of multiple class inheritance.