Skip to content

Instantly share code, notes, and snippets.

@kharioki
Created April 20, 2020 23:56
Show Gist options
  • Save kharioki/889ae220d13e5de8c794c87dd580145b to your computer and use it in GitHub Desktop.
Save kharioki/889ae220d13e5de8c794c87dd580145b to your computer and use it in GitHub Desktop.
class constructors in dart
// Class constructors
void main() {
Human june = Human(165, 120);
print(june.height);
print(june.weight);
Human tony = Human(170, 140);
print(tony.height);
print(tony.weight);
}
class Human {
// property
double height;
double weight;
int age = 24;
// constructor
// Human({double height, double weight}) {
// this.height = height;
// this.weight = weight;
// }
Human(this.height, this.weight);
// method
void grow(int numberOfYears) {
age = age + numberOfYears;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment