Notice
Recent Posts
Recent Comments
Link
Programmer
Class 본문
//Animal 클래스
class Animal {
//생성자
constructor(type, name, sound) {
this.type = type;
this.name = name;
this.sound = sound;
}
say() {
console.log(this.sound);
}
}
//Animal 클래스를 상속받는 Dog 클래스
class Dog extends Animal {
//생성자
constructor(name, sound) {
super("개", name, sound);
}
}
//Animal 클래스를 상속받는 Cat 클래스
class Cat extends Animal {
//생성자
constructor(name, sound) {
super("고양이", name, sound);
}
}
const dog = new Dog("멍멍이", "멍멍");
const cat = new Cat("야옹이", "야옹");
dog.say();
cat.say();
Comments