Default Constructor

Every class has a default constructor . The constructor is implicitly called whenever a

object is created from that class


void main() {
  
  
  var employee1 = Employee();
  
  
}



class Employee{
  
  int id;
 
  String firstname;
  
  String lastname; 
  
  String  position;
  
  int number_of_day_worked;
  
  
  
  
  // Looks like a function , but not a function 
  
  //Default Constructor 
  
  Employee(){
   
    
    print("A Default constructor constructing a object");
    

    
  }  
  
  
}

If you write a piece of code inside the default constructor , that piece of code will get executed when you create the object .

Last updated