Skip to content

Instantly share code, notes, and snippets.

@onumanfj
Created June 20, 2023 09:03
Show Gist options
  • Save onumanfj/3bf61f66a6a1a570c32dd2824762d351 to your computer and use it in GitHub Desktop.
Save onumanfj/3bf61f66a6a1a570c32dd2824762d351 to your computer and use it in GitHub Desktop.
dart - classes and objects 2

dart - classes and objects 2

Created with <3 with dartpad.dev.

void main() {
//objects
Car lexusEs300 = Car('grey');
print(lexusEs300.colour);
lexusEs300.drive();
lexusEs300.currentSpeed = 57.4;
lexusEs300.drive();
print(lexusEs300.numOfDoors);
}
class Car {
//constructors
Car (String newColour) {
colour = newColour;
}
//properties
int numOfDoors = 5;
late String colour;
double currentSpeed = 0;
//methods
void drive() {
print('moving at a speed of $currentSpeed MPH');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment