Static Variables and Methods
Last updated
Last updated
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";
}
void main() {
// Static instance variables
//-----------------------------
Employee.companyname="B";
print(Employee.companyname);
}
class Employee{
int id;
String name;
static String companyname="A";
}
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);
employee1.test();
}
class Employee{
int id;
String name;
static String companyname="A";
void test(){
// Accessing static fields inside a method
print(Employee.companyname);
}
}
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}");
}
}
void main() {
Employee.salary(30);
}
class Employee{
int id;
String name;
static void salary(int perDayWage){
print("Salary : ${perDayWage*20}");
}
}