super Keyword -1
This section covers using super keyword to invoke a method from the parent class
Last updated
This section covers using super keyword to invoke a method from the parent class
Last updated
The super keyword is a reference variable that is used to refer immediate parent class objects
void main() {
//super keyword -1
var manager1 = Manager();
manager1.id =1;
manager1.firstname="John";
manager1.lastname="Doe";
manager1.dayworked=30;
manager1.project ="Alpha";
manager1.salary(20);
}
class Employee {
int id;
int dayworked;
String firstname;
String lastname;
String fullname() {
return this.firstname + " " + this.lastname;
}
void salary(int perDaywage) {
print(this.dayworked * perDaywage);
}
}
// Manager Class
class Manager extends Employee {
//property
String project;
//Method
String manageproject(){
return "Managing project " + " " + this.project;
}
@override
void salary(int perDaywage) {
super.salary(perDaywage);
print((this.dayworked * perDaywage)+30);
}
}
void main() {
//super keyword -1
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 -super.salary(perDaywage));
}
}