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)