Dart 基本特征

私有属性/私有方法

import 'test88.dart';main() {var home = new MainHome();home.execRun(); //间接的调用私有方法
}class MainHome {String _name = "张三";//私有属性int age = 10;main() {_run();print(_name);}void _run() {print("私有方法");}execRun() {this._run();}
}
get用法
var rect = Rect(10, 2);var rect1 = Rect1(10, 2);print( "面积是= ${rect.area()}");print( "面积是= ${rect1.area}");//注意调用直接通过访问属性的方式访问arearect1.areaHeight=6;print( "面积是= ${rect1.area}");class Rect {num height;num width;Rect(this.height, this.width);//方法area() {return this.height * this.width;}
}class Rect1 {num height;num width;Rect1(this.height, this.width);//get用法get area {return this.height * this.width;}//方法set areaHeight(value) {this.height = value;}
}
构造函数体运行之前初始化实例变量
class Rect2 {num height;num width;//可以在构造函数体运行之前初始化实例变量Rect2():height =3,width=2 {print("height =$height ---- width=$width");}//get用法get area {return this.height * this.width;}//方法set areaHeight(value) {this.height = value;}
}