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
| package Lecture9;
public class Employee {
private String name;
private int salary;
private String grade;
private static int totalEmployee;
Employee(){
++Employee.totalEmployee;
}
Employee(String name, int salary, String grade){
this.name = name;
this.salary = salary;
this.grade = grade;
++Employee.totalEmployee;
}
void info() {
System.out.println("이름 : " + this.name + ", 연봉 : " + this.salary + ", 직급 : " + this.grade);
Employee.printTotalEmployee();
}
static void printTotalEmployee() {
System.out.println("총 사원수 : " + Employee.totalEmployee + "명");
}
String getName(){
return this.name;
}
int getSalary() {
return this.salary;
}
String getGrade() {
return this.grade;
}
void setSalary(int salary){
this.salary = salary;
}
}
|
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
| package Lecture9;
public class EmployeeMain {
public static void main(String[] args) {
// main 메소드에서는 객체생성과 메소드호출로만 구성되어있도록.
Employee.printTotalEmployee();
// Employee e = new Employee();
// e.name = "홍길동"; (직접 접근하는것은 좋지않다.)
Employee e = new Employee("홍길동", 3200, "사원");
e.info();
Employee e2 = new Employee("강길동", 4000, "주임");
e2.info();
Employee e3 = new Employee("윤길동", 3600, "사원");
e3.info();
Employee.printTotalEmployee();
System.out.println("사원명 : " + e.getName());
System.out.println("연봉 : " + e.getSalary());
System.out.println("직급 : " + e.getGrade());
e.setSalary(3800);
System.out.println("연봉 : " + e.getSalary());
}
}
|