首页 > 其他 > 详细

虚方法--重载

时间:2019-10-18 21:54:35      阅读:72      评论:0      收藏:0      [点我收藏+]

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();
        }
    }
}

虚方法--重载

原文:https://www.cnblogs.com/wbwhy/p/11700534.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!