Tsallaka zuwa abun ciki
Justice Tech School

Getters, Setters and Privacy

get and set define computed properties. A name starting with an underscore is private to its library (file).

Example
class Temp {
  double c;
  Temp(this.c);
  double get f => c * 9 / 5 + 32;
  set fahrenheit(double v) => c = (v - 32) * 5 / 9;
}
void main() {
  var t = Temp(100);
  print(t.f);
}

Exercise

Private marker.

int count = 0;

Quiz Test

How do you make a member private?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.