접근 제어자 - 클래스
/**
* 접근 제어자
* access modifier
* => public private proteced
*/
class Employee{
// 필드
private name:string; // private은 내부 class에서만 접근가능
protected age:number; // 파생 클래스까지는 허용해줌
public position:string; // 모두 접근 가능
// 생성자
constructor(name:string, age:number, position:string){
this.name = name;
this.age = age;
this.position = position;
}
// 위의 필드와 생성자를 이렇게 축약 가능
// 필드는 알아서 만들어줌 아래처럼 쓰면
//생성자
// constructor(private name:string, protected age:number, public position:string){}
// 메서드
work(){
console.log(`${this.name} 일함`)
}
}
class ExecutiveOfficer extends Employee {
// 필드
officeNumber: number;
// 생성자
constructor(name:string, age:number, position:string, officeNumber:number){
super(name, age, position);
this.officeNumber = officeNumber;
}
// 메서드
func(){
// this.name;
this.age
}
}
const employee = new Employee("박정수", 26, "developer");
// employee.name = "홍길동";
// employee.age = 30;
employee.position = "디자이너";