// A person. The implicit interface contains greet().classPerson{// In the interface, but visible only in this library.finalString_name;// Not in the interface, since this is a constructor.Person(this._name);// In the interface.Stringgreet(Stringwho)=>'Hello, $who. I am $_name.';}// An implementation of the Person interface.classImpostorimplementsPerson{Stringget_name=>'';Stringgreet(Stringwho)=>'Hi $who. Do you know who I am?';}StringgreetBob(Personperson)=>person.greet('Bob');voidmain(){print(greetBob(Person('Kathy')));// Hello, Bob. I am Kathy.print(greetBob(Impostor()));// Hi Bob. Do you know who I am?}
Extending a class
classPhone{voiduse(){_call();_sendMessage();}}// Use extends to create a subclassclassSmartPhoneextendsPhone{voiduse(){// use super to refer to the superclasssuper.use();_takePhotos();_playGames();}}