Pillars of flutter
- ABSTRACTION
- ENCAPSULATION
- INGERITANCE
- POLYMORPHISM
POLYMORPHISM
By inheriting from parent class, we want to remove method and add some different method
so we use '@override' and then that method or func. is written
void main(){
LevitatingCar myUnicorn = LevitatingCar();
myUnicorn.drive();
}
class Car {
int number_of_seats = 5;
void drive(){ // this drive not work on LevitatingCar
print('wheels turn'); class
}
}
class LevitatingCar extends Car {
@override // override remove drive() method of void drive(){ parent class Car and replace with print('glide forwards'); this new drive() method
}
}
void main(){
SelfdrivingCar myNamor = SelfdrivingCar('Atlantis');
myNamor.drive();
}
class SelfdrivingCar extends Car {
String destination;
SelfdrivingCar(String usersetDestination){
destination = usersetDestination;
}
@override
void drive(){
super.drive();
print('staring towards $destination');
}
}
output
wheels turn
staring towards Atlantis
Comments
Post a Comment