creating a constructor in flutter code example

Example 1: constructor in dart

//Creating object.
void main(){
  SelfDrivingCar myLamb = SelfDrivingCar('Floride');
  myLamb.drive();
 
}

//Initializing class Car.
class Car {
  int numberofwheels = 4;
  
  void drive() {
    print('this is a car');
  }
}

//using Inheritance 
class SelfDrivingCar extends Car {
  String destination='k';
  
  SelfDrivingCar(String userDestination){ //constructor
    destination = userDestination;
  }
  @override    //polymorphism.
  void drive() {
    super.drive();  // accessing parent's methods.
    
    print('sterring wheel to $destination');
    
  }
}

Example 2: constructor flutter

class Student{
  Student(int enNum){
    print(enNum);
  }
}

main(){
  var myStudent = new Student(15);
}