Illie

JS. 클래스 상속 본문

JAVASCRIPT/자바스크립트

JS. 클래스 상속

(*ᴗ͈ˬᴗ͈)ꕤ*.゚ 2022. 4. 15. 10:49

{
    class study {
        constructor(num, name, job){
            this.num = num;
            this.name = name;
            this.job = job;
        }
        result(){
            document.write(this.num + ".내 이름은 " + this.name + "이며, 직업은 " + this.job + "입니다.");
        }
    }

    class study2 extends study {
        constructor(num, name, job, age){
            super(num, name, job);
            this.age = age;
        }
        result2(){
            document.write(this.num + ".내 이름은 " + this.name + "이며, 직업은 " + this.job + "입니다. 나이는 " + this.age + "세 입니다.");
        }
    }

    const info1 = new study(1, "웹쓰", "웹퍼블리셔");
    const info2 = new study2(2, "웹스토리보이", "프론트엔드개발자", "20");

    info1.result();
    info2.result2();
}

'JAVASCRIPT > 자바스크립트' 카테고리의 다른 글

JS. 0415 오답노트  (0) 2022.04.15
JS. 부모, 자식, 형제 찾기, 선택하기  (0) 2022.04.15
JS. 클래스  (0) 2022.04.15
JS. 객체리터럴 함수  (0) 2022.04.15
JS. 프로토타입 함수  (0) 2022.04.15
Comments