您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“c#面向?qū)ο笾欣^承的案例分析”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“c#面向?qū)ο笾欣^承的案例分析”這篇文章吧。
School(object): __init__(self,name,addr): self.name=name self.addr=addr self.students=[] self.staffs=[] enroll(self,stu_obj): self.students.append(stu_obj) print(%stu_obj.name) hire(self,staff_obj): self.staffs.append(staff_obj) print(%staff_obj.name) SchoolMember(object): __init__(self,name,age,sex,hourse_name,hourse_id): self.name=name self.age=age self.sex=sex self.hourse_name=hourse_name self.hourse_id=hourse_id tell(self): Teacher(SchoolMember): __init__(self,name,age,sex,salary,course,hourse_name,hourse_id): super(Teacher,self).__init__(name,age,sex,hourse_name,hourse_id) self.salary=salary self.course=course tell(self): print(%(self.name,self.name,self.age,self.sex,self.salary,self.course,self.hourse_name,self.hourse_id)) teach(self): print(%(self.name,self.course)) Student(SchoolMember): __init__(self,name,age,sex,stu_id,grade,hourse_name,hourse_id): super(Student,self).__init__(name,age,sex,hourse_name,hourse_id) self.stu_id=stu_id self.grade=grade tell(self): print(%(self.name, self.name, self.age, self.sex, self.stu_id, self.grade,self.hourse_name,self.hourse_id)) pay_tuition(self,amount): print(%(self.name,amount)) school=School(,) t1=Teacher(,66,,7000,,,) t2=Teacher(,26,,6000,,,) s1=Student(,18,,,,,) s2=Student(,17,,,,,) t1.tell() t2.tell() s1.tell() s2.tell() school.hire(t1) school.hire(t2) school.enroll(s1) school.enroll(s2) t1.teach() t2.teach() print(school.students,school.staffs) stu school.students: stu.pay_tuition(5000)
以上是“c#面向?qū)ο笾欣^承的案例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。