Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C # case study of inheritance in object-oriented

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report