-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeSystem.java
More file actions
62 lines (55 loc) · 1.7 KB
/
EmployeeSystem.java
File metadata and controls
62 lines (55 loc) · 1.7 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
52
53
54
55
56
57
58
59
60
61
62
class Employee {
// Static Variables
private static String companyName = "ABC Company";
private static int totalEmployees = 0; // counter
// Instance Variables
private final int id;
private String name;
private String designation;
// Constructor
Employee(int id, String name, String designation) {
this.id = id;
this.name = name;
this.designation = designation;
totalEmployees++;
}
// Method to display employee details
public void displayDetails() {
if(this instanceof Employee) { // Using instanceof
System.out.println("Company Name: " + companyName);
System.out.println("Employee ID: " + id);
System.out.println("Employee Name: " + name);
System.out.println("Designation: " + designation);
System.out.println();
}
}
// Method to display total employees
public static void getTotalEmployees() {
System.out.println("Total Employees: " + totalEmployees);
}
}
// Main Class
public class EmployeeSystem {
public static void main(String[] args) {
// Create Objects of Employee Class
Employee emp1 = new Employee(1, "Aman", "Software Engineer");
Employee emp2 = new Employee(2, "Adarsh", "Manager");
// Display employee details
emp1.displayDetails();
emp2.displayDetails();
// Display total number of employees
Employee.getTotalEmployees();
}
}
// Sample Output ->
//Company Name: ABC Company
//Employee ID: 1
//Employee Name: Aman
//Designation: Software Engineer
//
//Company Name: ABC Company
//Employee ID: 2
//Employee Name: Adarsh
//Designation: Manager
//
//Total Employees: 2