changeAge(age: number) {
this.age = age;
}
}
// Cannot assign to 'age' because it is a read-only property.
class Child extends Parent {
constructor(name: string, age: number, married: boolean) {
super(name, age, married);
}
sayName() {
console.log(this.name);
}
sayMarried() {
console.log(this.married);
}
sayValue() {
console.log(this.value);
}
}
// Property 'value' is private and only accessible within class 'Parent'.
const child = new Child('zero', 28, false);
child.name;
child.married;
// Property 'married' is protected and only accessible within class 'Parent' and its subclasses.
child.value;
// Property 'value' is private and only accessible within class 'Parent'.