Last active
June 23, 2020 09:20
-
-
Save aryzae/a04e7cb2061765dc254c6e125f6c30e0 to your computer and use it in GitHub Desktop.
Flutter勉強会3回目の資料(抽象化クラス)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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