class Person {
constructor(name) {
this.name = name;
}
speak() {
console.log('Hello this is ' + this.name);
}
}
class Child extends Person {
// private property
#age; // 1we can access to age property only in this class
constructor(name, age) {
super(name);
this.#age = age; //2
}
}
const child = new Child('John', 10);
child.speak()
console.log(child.name);
// 3 if try to call age, we got an error !
console.log(child.age);
console.log(child.#age);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.