-1

In Dart i figure out that we can implement from an abstract class, is that possible, what I know from my background is: that we can only implement from an interface and extend from abstract, how's that is possible?

abstract class A{
      
      int aa;
     
      String bb;
     
      String c;
}
    
class B implements A{
      @override
      int aa= 100;
    
      @override
      String bb= "testtesttets";
    
      @override
      String cc= "testtesttets";
}
Ayoub Boumzebra
  • 3,885
  • 3
  • 21
  • 37
  • That sounds more like Java. This is not the case with dart. I would recommend doing some research and reading the [language tour](https://dart.dev/guides/language/language-tour#implicit-interfaces) before asking here. – Christopher Moore Aug 27 '20 at 16:35
  • @ChristopherMoore Thank you for your answer, but it doesn't answer my question, my question is: it is possible to implement from an abstract class? and why? because we only implement from an interface not abstract classes, right? – Ayoub Boumzebra Aug 27 '20 at 18:44
  • Your assumption "we only implement from an interface not abstract classes" is not completely correct. From the linked post "Every class implicitly defines an interface containing all the instance members of the class and of any interfaces it implements. " It's obviously possible, as evidenced by the example you posted. – Christopher Moore Aug 27 '20 at 18:45
  • @ChristopherMoore You mean that we can implement from both interface and abstract classes, right ? can you explain more, please? – Ayoub Boumzebra Aug 27 '20 at 18:48
  • What's more to explain? Every class implicitly defines an interface containing all the instance members of the class and of any interfaces it implements. Every class **is** an interface. – Christopher Moore Aug 27 '20 at 18:49
  • Thanks for your effort, but you didn't answer my question, I found that my answer here https://stackoverflow.com/q/35990538/7590031 – Ayoub Boumzebra Aug 27 '20 at 18:55
  • Typescript is a different language. What's stated there is not necessarily held true for dart. – Christopher Moore Aug 27 '20 at 18:55
  • But it is the same logic that I mentioned in my example – Ayoub Boumzebra Aug 27 '20 at 18:57
  • That does not mean what they say holds true for dart. – Christopher Moore Aug 27 '20 at 18:57

1 Answers1

1

Yes, you can implement the interface of an abstract class (and a non-abstract class, and a mixin too).

You can implement interefaces.

In Dart, all class declarations introduce an interface, and all mixin declarations introduce an interface. There is no separate interface declaration.

lrn
  • 64,680
  • 7
  • 105
  • 121