标签:
using System; using System.Collections.Generic; using System.Text; namespace 抽象类 { class Program { static void Main(string[] args) { /* Fruit f;//抽象类不能直接创建对象,一般用它来引用子类对象 f = new Apple(); f.chandi(); f = new Pineapple(); f.chandi(); Console.ReadLine(); //同一行代码“f.chandi()”,由于f所引用的对象不同而输出不同的结果。 可以按以下公式编写代码 抽象类 抽象类变量名=new 继承此抽象类的具体子类名();*/ parent p; p = new child(); p.Message = "Hello";//调用child中属性 Console.WriteLine(p.Message);//打印属性 Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Text; namespace 抽象类 { abstract class parent { public abstract string Message //抽象属性 { get; set; } } }
using System; using System.Collections.Generic; using System.Text; namespace 抽象类 { class child:parent { private string _msg; public override string Message //抽象类中的抽象属性,要在子类中实现 { get { return _msg; } set { _msg=value; } } } }
标签:
原文地址:http://www.cnblogs.com/happinesshappy/p/4526813.html