1.2:多态与重写.pdf

时间:2022-09-09 16:52:18
【文件属性】:
文件名称:1.2:多态与重写.pdf
文件大小:202KB
文件格式:PDF
更新时间:2022-09-09 16:52:18
1.2:多态与重写 重写,子类override,父类virtual, 用数组输出两个show,多态 Person[] persons = new Person[2]; Student stu = new Student("aaa", 20, true); Teacher t = new Teacher("aa", 12, false); persons[0] = stu; persons[1] = t; for (int i = 0; i < persons.Length; i++) { persons[i].show(); } Console.ReadKey(); 如果子类没有override 数组输出的是父类的show //Person p = new Student();

网友评论