예시 코드
class Human{
constructor(name,age){
this.name=name;
this.age=age;
}
sleep(){ return `${this.name}이(가) 잠을 잡니다.`}
} // Human class를 만들었다.
class Student extends Human{
constructor(name,age,grade){// subclass에 constructor가 있다면
super(name,age)//this를 사용하기전에 가장먼저 super()를 호출해야한다.
this.grade=grade;
}
study(){
return `${this.name}이(가) 공부를 합니다.`}
}// extends를 이용하여 Human클래스를 상속