虚方法--重载
程序员文章站
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;
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();
}
}
}