abstract
修饰符指示所修饰的内容缺少实现或未完全实现。
修饰符可用于类、方法、属性、索引器和事件。
在类声明中使用以指示某个类只能是其他类的基类。
标记为抽象或包含在抽象类中的成员必须通过从抽象类派生的类来实现。
抽象类不能实例化。
· 抽象类可以包含抽象方法和抽象访问器。
· 不能用 sealed修饰符修饰抽象类。
· 从抽象类派生的非抽象类必须包括继承的所有抽象方法和抽象访问器的实际实现。
override
扩展或修改继承的方法、属性、索引器或事件的抽象实现或虚实现
virtual
关键字用于修饰方法、属性、索引器或事件声明,并使它们可以在派生类中被重写。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Abstract
{
abstract class 龙
{
protected int _风 = 20;
protected int _火 = 20;
protected int _雷 = 20;
protected int _电 = 20;
protected int _雨 = 20;
public abstract void StrengThen();
public virtual void Attack()
{
StrengThen();
System.Console.WriteLine("风=" + this._风);
System.Console.WriteLine("火=" + this._火);
System.Console.WriteLine("雷=" + this._雷);
System.Console.WriteLine("电=" + this._电);
System.Console.WriteLine("雨=" + this._雨);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Abstract
{
class 风 : 龙
{
public override void StrengThen()
{
this._雨 = 0;
this._火 = 0;
this._雷 = 0;
this._电 = 0;
this._风 = 100;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Abstract
{
class 火 : 龙
{
public override void StrengThen()
{
this._雨 = 0;
this._火 = 100;
this._雷 = 0;
this._电 = 0;
this._风 = 0;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Abstract
{
class 雷 : 龙
{
public override void StrengThen()
{
this._雨 = 0;
this._火 = 0;
this._雷 = 100;
this._电 = 0;
this._风 = 0;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Abstract
{
class 电 : 龙
{
public override void StrengThen()
{
this._雨 = 0;
this._火 = 0;
this._雷 = 0;
this._电 = 100;
this._风 = 0;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Abstract
{
class 雨 : 龙
{
public override void StrengThen()
{
this._雨 = 100;
this._火 = 0;
this._雷 = 0;
this._电 = 0;
this._风 = 0;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Abstract
{
class 保护 : 龙
{
public override void StrengThen()
{
this._雨 = 0;
this._火 = 0;
this._雷 = 0;
this._电 = 0;
this._风 = 0;
}
public override void Attack()
{
System.Console.WriteLine("风=" + this._风);
System.Console.WriteLine("火=" + this._火);
System.Console.WriteLine("雷=" + this._雷);
System.Console.WriteLine("电=" + this._电);
System.Console.WriteLine("雨=" + this._雨);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Abstract
{
class Program
{
static void Main(string[] args)
{
龙 龙 = null;
string[] Attack = {"风","火","雷","电","雨","保护"};
foreach (string Item in Attack)
{
switch (Item)
{
case "风":
龙 = new 风();
break;
case "火":
龙 = new 火();
break;
case "雷":
龙 = new 雷();
break;
case "电":
龙 = new 电();
break;
case "雨":
龙 = new 雨();
break;
default:
龙 = new 保护();
break;
}
龙.Attack();
}
}
}
}