-
Notifications
You must be signed in to change notification settings - Fork 0
/
Encapsulation.java
43 lines (35 loc) · 886 Bytes
/
Encapsulation.java
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
public class Encapsulation {
public static void main(String[] args) {
Employee emp = new Employee();
emp.setName("John");
emp.setAge(30);
emp.setSalary(50000);
System.out.println("Name: " + emp.getName());
System.out.println("Age: " + emp.getAge());
System.out.println("Salary: $" + emp.getSalary());
}
}
class Employee {
private String name;
private int age;
private double salary;
// Getter and setter methods
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}