欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

虚方法--重载

程序员文章站 2023-12-27 20:32:39
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace ConsoleApplication1{ public ......

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

上一篇:

下一篇: