TypeScript
코딩앙마 타입스크립트 기초 강의 2
code10
2022. 9. 7. 18:05
#6 클래스
//접근 제한자(Access modifier) - public, private(#), protected
/*
public - 자식 클래스, 클래스 인스턴스 모두 접근 가능
private(#) - 해당 클래스 내부에서만 접근 가능
protected - 자식 클래스에서만 접근 가능
*/
class Car {
readonly name: string = "car";
color: string;
constructor(color: string, name: string){
this.color = color;
this.name = name;
}
start(){
console.log("start");
console.log(this.name);
}
}
class Bmw extends Car {
constructor(color: string, name: string){
super(color, name);
}
showName(){
console.log(super.name);
}
}
const z4 = new Bmw("black", "zzzz4")
//추상 class
abstract class Car {
color: string;
constructor(color: string){
this.color = color;
}
start(){
console.log("start");
}
abstract doSomething():void;
}
class Bmw extends Car {
constructor(color: string){
super(color);
}
doSomething(){
alert(3);
}
}
const z4 = new Bmw("black");
#6 Generic