Created
October 31, 2019 16:14
-
-
Save YBCS/eead0cd86ffd8238d6e310451566ef50 to your computer and use it in GitHub Desktop.
#1 codelabs --> Intro to Dart for Java devs!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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