类可以继承任何一个类或多个接口。而接口可以多重继承接口。
1.创建一个People类,并在其中嵌套两个类Worker和Student,对于嵌套的类也有两种实现的方法。
1: namespace 类的嵌套2: {
3: class Program4: {
5: static void Main(string[] args)6: {
7: Console.WriteLine("People的方法有:");8: People myPeople = new People();9: myPeople.eat();
10: myPeople.sleep();
11: People.Worker myWorker = new People.Worker();12: myWorker.work();
13: People.Student myStudent = new People.Student();14: myStudent.study();
15:
16: Console.ReadLine();
17: }
18:
19: }
20: class People21: {
22:
23: public void eat()24: {
25: Console.WriteLine("eat");26: }
27:
28: public void sleep()29: {
30: Console.WriteLine("sleep");31: }
32:
33: public class Worker34: {
35: public void work()36: {
37: Console.WriteLine("study");38: }
39: }
40:
41: public class Student42: {
43: public void study()44: {
45: Console.WriteLine("sleep");46: }
47: }
48: }
49: }
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240803130933255-1404888097.jpg)