class Student {
String id;
String name;
int age;
double score;
Student() {
print("Default Constructor");
}
Student.fromId(String id) {
this.id = id;
}
Student.fromIdAndName(String id, String name) {
this.id = id;
this.name = name;
}
Student.full(String id, String name, int age, double score) {
this.id = id;
this.name = name;
this.age = age;
this.score = score;
}
}
void main() {
var student1 = new Student();
var student2 = new Student.fromId("st01");
print("Student 2 Info");
print("id: ${student2.id}");
var student3 = new Student.full("st02", "name 2", 22, 6.7);
print("Student 3 Info");
print("id: ${student3.id}");
print("name: ${student3.name}");
print("age: ${student3.age}");
print("score: ${student3.score}");
}
Default Constructor
Student 2 Info
id: st01
Student 3 Info
id: st02
name: name 2
age: 22
score: 6.7