AnasB

OOP class 2

Oct 22nd, 2021
747
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Car{
  2.   int noOfSeat=4;
  3.   void drive() {
  4.     print("this is driving");
  5.   }
  6. }
  7.  
  8. class ElectricCar extends Car{
  9.   int batteryLevel=0;
  10.   void recharge(){
  11.     this.batteryLevel=100;
  12.     print('Charging is %100');
  13.   }
  14. }
  15.  
  16. class SelfDrivingCar extends Car{
  17.   String destination;
  18.   SelfDrivingCar({this.destination});
  19.   @override
  20.   void dive() {
  21.     super.drive();
  22.     print("the car is moving to $destination");
  23.   }
  24. }
  25.  
  26. void main(){
  27.   var normal= Car();
  28.   normal.drive();
  29.   var tesla=ElectricCar();
  30.   tesla.drive();
  31.   var myWaymo = SelfDrivingCar(destination: "Bazzar");
  32.   myWaymo.drive();
  33. }
RAW Paste Data