Skip to content

Instantly share code, notes, and snippets.

@freedive-cebu30
Last active April 7, 2022 05:48
Show Gist options
  • Save freedive-cebu30/c97ae48fa15b4572757109c5197d8cb1 to your computer and use it in GitHub Desktop.
Save freedive-cebu30/c97ae48fa15b4572757109c5197d8cb1 to your computer and use it in GitHub Desktop.
class_12
class Person {
String? _name;
int? _age;
Person(String name, int age) {
_name = name;
_age = age;
}
void introduce() {
print(_name! + ':' + _age.toString());
}
// ゲッター
String get name {
return _name!;
}
// セッター
set name(newName) {
_name = newName;
}
}
void main() {
Person jojo = Person('jojo', 30);
print(jojo.name);
// jojo
jojo.name = 'Duo';
print(jojo.name);
// Duo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment