Last active
          April 20, 2020 22:37 
        
      - 
      
- 
        Save kharioki/c094f58e10b1d95da57ef69ff7eea245 to your computer and use it in GitHub Desktop. 
    Inheritance of Action
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | // Inheritance of Actions | |
| void main() { | |
| // Car myNormalCar = Car(); | |
| // myNormalCar.drive(); | |
| // print(myNormalCar.numberOfSeats); | |
| ElectricCar myTesla = ElectricCar(); | |
| myTesla.drive(); | |
| // using polymorphism | |
| SelfDrivingCar myWaymo = SelfDrivingCar('Waiyaki way'); | |
| myWaymo.drive(); | |
| } | |
| class Car { | |
| int numberOfSeats = 5; | |
| void drive() { | |
| print('Wheels turn'); | |
| } | |
| } | |
| class ElectricCar extends Car { | |
| int batteryLevel = 100; | |
| void recharge() { | |
| batteryLevel = 100; | |
| } | |
| } | |
| class LevitatingCar extends Car { | |
| // polymorphism | |
| // override the drive function | |
| @override | |
| void drive() { | |
| print('glide forwards'); | |
| } | |
| } | |
| class SelfDrivingCar extends Car { | |
| // create a new propperty set when you create a new car | |
| String destination; | |
| SelfDrivingCar(String userSetDestination){ | |
| destination = userSetDestination; | |
| } | |
| @override | |
| void drive() { | |
| super.drive(); | |
| print('steering towards $destination'); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment