-
-
Save Sfshaza/e57aa06401e6618d4eb8 to your computer and use it in GitHub Desktop.
ch02
This file contains 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
class Person { | |
String firstName; | |
Person.fromJson(Map data) { | |
print('in Person'); | |
} | |
} | |
class Employee extends Person { | |
// Person does not have a default constructor; | |
// you must call super.fromJson(data). | |
Employee.fromJson(Map data) : super.fromJson(data) { | |
print('in Employee'); | |
} | |
} | |
main() { | |
var emp = new Employee.fromJson({}); | |
// Prints: | |
// in Person | |
// in Employee | |
if (emp is Person) { | |
// Type check | |
emp.firstName = 'Bob'; | |
} | |
(emp as Person).firstName = 'Bob'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment