当前位置: 移动技术网 > IT编程>开发语言>c# > 虚方法--重载

虚方法--重载

2019年10月19日  | 移动技术网IT编程  | 我要评论

using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.threading.tasks;
namespace consoleapplication1
{
   public class vehicle
    {
        public float weight;
        public vehicle(float w)
        {
            weight = w;
        }
        public virtual void show()
        {
            console.writeline("the weight of vehicle is:" + weight);
        }
    }
    public class car:vehicle
    {
        int passengers;
    public car(float w,int p):base(w)
        {
            passengers = p;
        }
        public override void show()
        {
            base.show();
            console.writeline("the passengers of car is:" + passengers);
        }
    }
    class test
    {
        static void main(string[] args)
        {
            car c = new car(6, 100);
            c.show();
            console.read();
        }
    }
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网