ylbtech-.NET Framework: 类的继承关系,多态的体现,我的觉得题目还是有点欠缺 |
1.A,案例 |
类的继承关系,多态的体现,我的觉得题目还是有点欠缺。
1.B,解决方案 |
using System; namespace ConsoleApplication1 { class People { int age = 8; public int Age { get { return age; } } } /// <summary> /// Student 类里写的有点多余 /// </summary> class Student : People { int age = 9; public int Age { get { return age; } } } class Program { static void Main(string[] args) { //父类引用子类对象(多态) People p = new Student(); Console.WriteLine(string.Format("age={0}", p.Age)); Student s = new Student(); Console.WriteLine(string.Format("age={0}",s.Age)); } } }
1.C,运行结果 |
age=8 age=9 请按任意键继续. . .
,如需转载请自行联系原作者