1 Star 0 Fork 28

jinxi/dart_in_action

forked from ryanpenn/dart_in_action
暂停
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
07_class_and_objects.dart 614 Bytes
一键复制 编辑 原始数据 按行查看 历史
ryanpenn 提交于 2019-03-27 10:55 . dart programming
///
/// class and objects
///
main(List<String> args) {
var student = Student(1);
student.name = "Peter";
student.study();
var tom = Student(2, name: 'Tom');
tom.study();
var robot = Student.myCustomConstructor();
robot.study();
}
class Student {
// 下划线开头的表示私有(private)
int _id = -1;
String name;
// 构造函数赋值
Student(this._id, {this.name});
// 自定义构造函数
Student.myCustomConstructor() {
_id = 0;
name = 'Robot';
}
// 属性(读)
int get id => _id;
void study() {
print("${this.name}(No.$_id) is now studying");
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Dart
1
https://gitee.com/jinxi17/dart_in_action.git
git@gitee.com:jinxi17/dart_in_action.git
jinxi17
dart_in_action
dart_in_action
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385