Dart by Example: Getters and Setters
1. import 'dart:math';
3. class Position {
4. int _x;
5. int _y;
7. Position(this._x, this._y);
9. double get rad => atan2(_y, _x);
11. void set x(int val) {
12. _x = val;
13. }
14. }
16. main() {
17. var p = new Position(2, 3);
18. p.x = 10;
19. print('x: ${p._x} y: ${p._y}');
20. print('rad: ${p.rad}');
21. }
1. $ getters_setters.dart
2. x: 10 y: 3
3. rad: 0.2914567944778671
