late int age;
//姓名
late String name;
}
main() {
var people = People();
people.name = “张三”;
people.age = 18;
}
带有构造方法的类
class People {
//年龄
late int age;
//姓名
late String name;
People(int age, String name) {
this.age = age;
this.name = name;
}
}
main() {
var people = People(18,“张三”);
}
构造方法简写形式(类(this.属性))
class People {
//年龄
late int age;
//姓名
late String name;
People(this.age, this.name);
}
main() {
var people = People(18, “张三”);
print(“姓名: p e o p l e . n a m e , 年 龄 : {people.name},年龄: