@override annotation

@override annotation explicitly tells the compiler you are trying to override a parent class method . All kinds of IDE uses override annotation to help the developer in various way . Also it improves the readability of the code

void main() {
  
  
  // @override annotation 

  var manager1 = Manager();
  
  
  manager1.id =1;
  manager1.firstname="John";
  manager1.lastname="Doe";
  manager1.dayworked=30;
  
  manager1.project ="Alpha";
  
  print(manager1.salary(20));

  
  
  
  
}

class Employee {
  int id;
  int dayworked;
  String firstname;
  String lastname;

  String fullname() {
    return this.firstname + " " + this.lastname;
  }

  int salary(int perDaywage) {
    return (this.dayworked * perDaywage);
  }
}




// Manager Class 


class Manager extends Employee {
  
  
  //property 
   String project;
 
  
  //Method 
  
  String manageproject(){
    
    return "Managing project " + " " + this.project; 
  }
  
   
  @override
   int salary(int perDaywage) {
    return ((this.dayworked * perDaywage)+30);
  }
  
 
}

Although it's not mandatory but it's good practice to use @override annotation . When you will be using an IDE , almost all the time @override annotation is automatically added ,so you don't need to worry about it

Last updated