Skip to content

Commit 0c70f18

Browse files
committed
dart: getters and setters in dart
Signed-off-by: Ayush Dubey <ayushdubey70@gmail.com>
1 parent f1c7d8a commit 0c70f18

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

dart/getterSetters.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'dart:math';
2+
3+
class Position {
4+
int _x;
5+
int _y;
6+
7+
Position(this._x, this._y);
8+
9+
double get rad => atan2(_y, _x);
10+
11+
void set x(int val) {
12+
_x = val;
13+
}
14+
}
15+
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+
}

0 commit comments

Comments
 (0)