Skip to content

Instantly share code, notes, and snippets.

@faizan1947
Last active July 16, 2022 07:14
Show Gist options
  • Save faizan1947/00c6fa0d941e6dc6167fa317706f60d7 to your computer and use it in GitHub Desktop.
Save faizan1947/00c6fa0d941e6dc6167fa317706f60d7 to your computer and use it in GitHub Desktop.
Polymorphism
void main() {
//Object
var selfCar = SelfDrivingCar(destination: 'Lasani colony');
selfCar.run();
}
class Car {
int seats = 4;
void run() {
print('Car is running');
}
}
class SelfDrivingCar extends Car {
String? destination;
SelfDrivingCar({this.destination});
@override
void run() {
super.run(); //calling parent class method
print('steering towards $destination');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment