typescript
Copy
class Person {
protected name: string;
protected age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
public getName(): string {
return this.name;
}
public getAge(): number {
return this.age;
}
}
class Student extends Person {
private studentId: string;
constructor(name: string, age: number, studentId: string) {
super(name, age);
this.studentId = studentId;
}
public getStudentId(): string {
return this.studentId;
}
}
// Usage
const student = new Student("Jane Doe", 20, "S12345");
console.log(student.getName()); // Output: Jane Doe
console.log(student.getAge()); // Output: 20
console.log(student.getStudentId()); // Output: S12345