Basic concept of Inheritance
Types of Inheritance & Terminology
void main() {
// Inheritance Example
var developer1 = Developer();
var manager1 = Manager();
developer1.id = 1;
developer1.firstname = "John";
developer1.lastname = "Doe";
developer1.dayworked = 12;
developer1.proglanguage = "Dart";
manager1.id = 2;
manager1.firstname = "Jane";
manager1.lastname = "Doe";
manager1.dayworked = 12;
manager1.project = "Alpha";
print(developer1.id);
print(developer1.firstname);
print(developer1.lastname);
print(developer1.dayworked);
print(developer1.fullname());
print(developer1.salary(20));
print(developer1.coding());
print("------------");
print(manager1.id);
print(manager1.firstname);
print(manager1.lastname);
print(manager1.dayworked);
print(manager1.fullname());
print(manager1.salary(20));
print(manager1.manageproject());
}
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);
}
}
// Developer Class
class Developer extends Employee {
//property
String proglanguage;
// Method
String coding() {
return "Coding in " + " " + this.proglanguage;
}
}
// Manager Class
class Manager extends Employee {
//property
String project;
//Method
String manageproject(){
return "Managing project " + " " + this.project;
}
}
Note: There is a typo . Used "manager1.dayworked = 12" instead of
"manager1.dayworked = 10"