Created with <3 with dartpad.dev.
Last active
July 16, 2022 07:14
-
-
Save faizan1947/00c6fa0d941e6dc6167fa317706f60d7 to your computer and use it in GitHub Desktop.
Polymorphism
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() { | |
//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