Methods
Last updated
Last updated
Functions declared inside a class are called "Methods"
void main() {
var employee1 = Employee(); // Creating employee1 object
var employee2 = Employee(); // Creating employee2 object
//Attribute <=> Instance Variable <=> Field Variable
// Setting the instance variable of employee1 object
employee1.id =1;
employee1.firstname ="John";
employee1.lastname ="Doe";
employee1.position = "CTO";
employee1.number_of_day_worked=12;
employee2.id =2;
employee2.firstname ="Jane";
employee2.lastname ="Doe";
employee2.position ="CEO";
employee2.number_of_day_worked=10;
// companyname for employee2 will be set to "A" , because we
// didn't set it, it take the default value from class
// Methods Calling <=> Invoke method
//
employee1.team_meeting_schedule();
employee1.calculate_salary();
employee1.fullname();
}
class Employee{
int id;
String firstname;
String lastname;
String position;
int number_of_day_worked;
//Methods for Employee class
void team_meeting_schedule(){
// logic for team_meeting
print("logic for Team meeting schedule");
}
void fullname(){
//logic for calculating fullname
print("logic for Full name");
}
void calculate_salary(){
// logic for calculating salary
print("logic for Calculate Salary");
}
}