Skip to content

Instantly share code, notes, and snippets.

@aryzae
Last active June 23, 2020 09:20
Show Gist options
  • Save aryzae/a04e7cb2061765dc254c6e125f6c30e0 to your computer and use it in GitHub Desktop.
Save aryzae/a04e7cb2061765dc254c6e125f6c30e0 to your computer and use it in GitHub Desktop.
Flutter勉強会3回目の資料(抽象化クラス)
void main() {
// error
Animal animal0 = Animal();
Animal animal1 = Mike();
print(animal1.breed);
animal1.bark();
Animal animal2 = Shiba();
print(animal2.breed);
animal2.bark();
}
abstract class Animal {
Animal();
// field
String breed;
// method
void bark();
}
class Mike implements Animal {
String breed = 'Cat';
void bark() {
print('meow');
}
}
class Shiba implements Animal {
get breed => 'Dog';
set breed(String newValue) => breed = newValue;
void bark() {
print('bow-wow');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment