虚方法--重载
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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();
}
}
}
{
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();
}
}
}
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步