Parameterised Constructor with Syntactic sugar

void main() {
  // Parameterised Constructor with syntactic sugar

  
  
  
  var employee1 = Employee(1, "John", "Doe", "CTO", 12);

  print(employee1.id);
  print(employee1.firstname);
  print(employee1.lastname);
  print(employee1.position);
  print(employee1.number_of_day_worked);
}

class Employee {
  int id;

  String firstname;

  String lastname;

  String position;

  int number_of_day_worked;
  
  
  

  //  Basic Parameterised Constructor 

//   Employee(id, firstname, lastname, position, number_of_day_worked) {
//     this.id = id;
//     this.firstname = firstname;
//     this.lastname = lastname;
//     this.position = position;
//     this.number_of_day_worked = number_of_day_worked;
//   }

  //  Parameterised Constructor  with  syntactic sugar

Employee(this.id,this.firstname,this.lastname,this. position,this. number_of_day_worked);

}


Last updated