Static Variables and Methods
Static Variables
void main() {
// Static instance variables
//-----------------------------
var employee1 = Employee();
employee1.id =1;
employee1.name="John Doe";
Employee.companyname="B";
print(employee1.id);
print(employee1.name);
print(Employee.companyname);
}
class Employee{
int id;
String name;
static String companyname="A";
}
Static methods
void main() {
// Static methods
//-----------------------------
var employee1 = Employee();
employee1.id =1;
employee1.name ="John Doe";
Employee.salary(30);
}
class Employee{
int id;
String name;
static void salary(int perDayWage){
print("Salary : ${perDayWage*20}");
}
}
Last updated
Was this helpful?