Created with <3 with dartpad.dev.
Created
June 20, 2023 09:03
-
-
Save onumanfj/3bf61f66a6a1a570c32dd2824762d351 to your computer and use it in GitHub Desktop.
dart - classes and objects 2
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
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