The current repo belongs to Paused status, and some functions are restricted. For details, please refer to the description of repo status
18 Star 81 Fork 26

ryanpenn / dart_in_action
Paused

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
07_class_and_objects.dart 614 Bytes
Copy Edit Raw Blame History
ryanpenn authored 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");
}
}
Dart
1
https://gitee.com/ryanpenn/dart_in_action.git
git@gitee.com:ryanpenn/dart_in_action.git
ryanpenn
dart_in_action
dart_in_action
master

Search