Skip to content

Instantly share code, notes, and snippets.

@YBCS
Created October 31, 2019 16:14
Show Gist options
  • Save YBCS/eead0cd86ffd8238d6e310451566ef50 to your computer and use it in GitHub Desktop.
Save YBCS/eead0cd86ffd8238d6e310451566ef50 to your computer and use it in GitHub Desktop.
#1 codelabs --> Intro to Dart for Java devs!
class Bicycle {
int cadence;
int _speed = 0; // makes it private
// private so explicit -- getter
int get speed => _speed;
// implicit getters and setters for all public instance variables
int gear;
Bicycle(this.cadence, this.gear);
void applyBrake(int decrement) {
_speed -= decrement;
}
void speedUp(int increment) {
_speed += increment;
}
//${expression}
@override
String toString() => 'Bicycle: $_speed mph';
}
// if cmd line arg required
// void main(List<String> args) {}
void main() {
// var bike = new Bicycle(2, 1);
var bike = Bicycle(2, 1);
print(bike);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment