-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
41 lines (32 loc) · 911 Bytes
/
Employee.java
File metadata and controls
41 lines (32 loc) · 911 Bytes
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
public class Employee {
private String name;
private double salary;
public Employee(String name, double salary) {
this.name = name;
this.salary = salary;
}
// Below are the setter and getter methods to maintain encapsulation and abstraction
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public void display() {
System.out.println("Employee Name: " + name);
System.out.println("Employee Salary: " + salary);
}
public static void main(String[] args) {
Employee emp = new Employee("John", 50000.0);
emp.display();
//Demonstrating setters
emp.setSalary(60000);
emp.display();
}
}