1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace ClassTrining 7 { 8 class 基类与派生类 9 { 10 } 11 12 /// <summary> 13 /// 基类BaseClass 14 /// </summary> 15 public class BaseClass 16 { 17 } 18 /// <summary> 19 /// 派生类MyClass,继承于BaseClass基类,一个类只能继承一个基类 20 /// </summary> 21 public class mali : BaseClass 22 { 23 24 } 25 /// <summary> 26 /// 抽象类,这个类只能做其它类的基类,用abstract关键字声明抽象类 27 /// </summary> 28 public abstract class myAbsClass 29 { 30 public abstract void dosomesthin(); 31 32 public virtual string GetName() 33 { 34 return "MetroX"; 35 } 36 } 37 /// <summary> 38 /// 继承抽象基类 39 /// </summary> 40 public class MyClasskk : myAbsClass 41 { 42 public override void dosomesthin() 43 { 44 45 } 46 47 public override string GetName() 48 { 49 //return base.GetName(); 50 return "Hello"; 51 } 52 } 53 }
时间: 2024-11-10 10:43:02