Skip to content

Instantly share code, notes, and snippets.

@sedera-tax
Last active January 20, 2021 11:04
Show Gist options
  • Save sedera-tax/6fc8adadb5efe6c6aff267c9334ce010 to your computer and use it in GitHub Desktop.
Save sedera-tax/6fc8adadb5efe6c6aff267c9334ce010 to your computer and use it in GitHub Desktop.
DART POO
void main() {
Car myCar = new Car('March', 'Nissan', 'blue', 5, false);
print(myCar.toString());
myCar.setColor('red');
print(myCar.toString());
print(myCar.getIsSUV());
Car suvCar = new Car('Juke', 'Nissan', 'black', 7, true);
print(suvCar.toString());
print(suvCar.getIsSUV());
CarSportive myCarSport = new CarSportive('GT-R Sports', 'Nissan', 'red', 5, false, 'rallye');
myCarSport.setColor('white');
print(myCarSport.toString());
print(myCarSport.getIsSUV());
}
class Car {
String name;
String mark;
String color;
int nbPlace;
bool isSUV;
Car(String myName, String myMark, String myColor, int myNbPlace, bool isSUV) {
this.name = myName;
this.mark = myMark;
this.color = myColor;
this.nbPlace = myNbPlace;
this.isSUV = isSUV;
}
String toString() {
return this.name + " est une voiture de marque " + this.mark + " (" + this.color + ") avec " + this.nbPlace.toString() + " places";
}
void setColor(String newColor) {
this.color = newColor;
}
bool getIsSUV() {
return this.isSUV;
}
}
class CarSportive extends Car {
String utility;
CarSportive(String myName, String myMark, String myColor, int myNbPlace, bool isSUV, String myUtility) : super(myName, myMark, myColor, myNbPlace, isSUV) {
this.utility = myUtility;
}
String toString() {
return this.name + " est une voiture sportive de marque " + this.mark + " (" + this.color + ") avec " + this.nbPlace.toString() + " places et est utilisée pour du " + this.utility;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment