Get the App
SLTechnology News&Howtos  ›  Development  › 

C # case study of inheritance in object-oriented

Shulou Source: shulou.com Published: 2022-06-02 02:18:45 10月02日 Update

This article mainly shows you the "case analysis of inheritance in c#object-oriented", the content is simple and easy to understand, and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn the article "case analysis of inheritance in c#object-oriented".

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) The above is "C#object-oriented inheritance case analysis" All the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Objects cases case studies caching relaying analysis content articles learning help easy to understand more organization knowledge editing industry information information channels channels research Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker MariaDB Apple MySQL