생성자 (Constructor)
class Employee{
int number; //사원
String name; // 이름
String title; // 직급
String dept; // 부서
//Employee(){super();}
Employee(int number, String name, String title, String dept){
this.number = number;
this.name = name;
this.title = title;
this.dept = dept;
}
}
public class ConstructorTest {
public static void main(String[] args) {
// 명령행 매개변수 4개 전달
// Employee 객체 생성하면서 멤버변수값 초기화
Employee e = new Employee(
Integer.parseInt(args[0]),args[1],args[2],args[3]);
Employee e2 = new Employee(
2000,"김한국","대리","키트리");
System.out.println("[사원] "+e.name+" [사번] "+e.number+
" [직급] "+e.title+" [부서] "+e.dept);
System.out.println("[사원] "+e2.name+" [사번] "+e2.number+
" [직급] "+e2.title+" [부서] "+e2.dept);
}
}