-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeManagementSystem.java
More file actions
51 lines (42 loc) · 1.51 KB
/
EmployeeManagementSystem.java
File metadata and controls
51 lines (42 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Employee {
private static String companyName = "Technical Innovation";
private static int totalEmployees = 0;
private final int id;
private String name;
private String designation;
// Constructor using 'this' to initialize fields
public Employee(int id, String name, String designation) {
this.id = id;
this.name = name;
this.designation = designation;
totalEmployees++;
}
// Static method to display the total number of employees
public static void displayTotalEmployees() {
System.out.println("Total Employees: " + totalEmployees);
}
// Method to display employee details
public void displayDetails() {
System.out.println("ID: " + id + ", Name: " + name + ", Designation: " + designation);
}
}
public class EmployeeManagementSystem {
public static void main(String[] args) {
// Create Employee instances
Employee emp1 = new Employee(1, "Ajay", "Front-end Developer");
Employee emp2 = new Employee(2, "Arun", "Back-end Developer");
// Display employee details if they are instances of Employee
if (emp1 instanceof Employee) {
emp1.displayDetails();
}
if (emp2 instanceof Employee) {
emp2.displayDetails();
}
// Display total employees
Employee.displayTotalEmployees();
}
}
//SampleOutput
//ID: 1, Name: Ajay, Designation: Front-end Developer
//ID: 2, Name: Arun, Designation: Back-end Developer
//Total Employees: 2