class Animal {
#type;
constructor(name, type) {
if (this.constructor === Animal) {
throw new Error("Нельзя создать экземпляр абстрактного класса Animal.");
}
this.name = name;
this.#type = type;
}
makeSound() {}
set type(value) {
this.#type = value;
}
get type() {
return this.#type;
}
}
// Конкретные классы
class Dog extends Animal {
makeSound() {
return "Woof!";
}
}
const dog1 = new Dog("Viktor", "Animal");
dog1.type = "Animal2";
console.log(dog1.type);