Dart编程实例 - dart getters 和 setters
本文为大家分享 Dart编程实例 - dart getters 和 setters 的具体示例代码,提供大家参考,具体内容如下:
class Student { String name; int age; String get stud_name { return name; } void set stud_name(String name) { this.name = name; } void set stud_age(int age) { if(age<= 0) { print("Age should be greater than 5"); } else { this.age = age; } } int get stud_age { return age; } } void main() { Student s1 = new Student(); s1.stud_name = 'MARK'; s1.stud_age = 0; print(s1.stud_name); print(s1.stud_age); }
本文为大家分享 Dart编程实例 - 类继承 的具体示例代码,提供大家参考,具体内容如下:void main() { var obj = new Circle(); obj.cal_area();} clas ...