编辑代码

class Person {
    public name: string // 公共的,所有地方都可以使用
    protected asset: number = 5000 // 受保护的,可以在内部和子类使用
    private idCard: string  // 私有的,可以只能在类内部使用,实例化对象也不能使用
    constructor(name: string, idCard: string){
        this.name = name
        this.idCard = idCard
    }
    getIdCard(): string {
        // 返回
        return this.idCard
    }
    getMyAssert(): number {
        return this.asset
    }
    setMyAssert(asset: number): void {
        this.asset = asset
    }
    
}

class Student extends Person {
    public school: string
    constructor(name: string, idCard:string, school:string){
        super(name,idCard)
        this.school = school
    }
    studentInfo(){
        console.log("我可以获取到父亲的资产: ",this.asset)
    }
    borrowMoney(money: number){
        // 借钱函数
        this.asset -= money
        console.log("借钱:", money, "还有:", this.asset)
    }
}
let li = new Person("张三", "1245444")
let s1 = new Student("小红", "4456123", "小学")

console.log("父的资产:", li.getMyAssert())
s1.studentInfo()
s1.borrowMoney(450)