interface-5 class

홍인열·2021년 8월 11일
0
interface IPerson1 {
  name: string;
  age?: number;
  hello(): void;
}


//implements 를 이용해 interface의 내용을 바탕으로 class을 생성
class Person implements IPerson1 {
  name: string;
  age?: number | undefined;

  constructor(name: string) {
    this.name = name;
  }

  hello(): void {
    console.log(`안녕하세요 ${this.name} 입니다.`);
  }
}

const person = new Person("Hinyc");

person.hello();
//=> 안녕하세요 Hinyc 입니다.
console.log(person.name);
//=> Hinyc
profile
함께 일하고싶은 개발자

0개의 댓글