- using System;
- namespace _03_05
- {
- class Car
- {
- public string color;
- private float weight;
- private DateTime releasedate;
- public static int count;
- public Car() // 无参数的构造函数
- {
- color = "Red";
- weight = 1.0F;
- releasedate = DateTime.Today;
- }
- public Car(string Color, float Weight) // 有参数的构造函数
- {
- color = Color;
- weight = Weight;
- releasedate = DateTime.Today;
- }
- public void Run()
- {
- Console.WriteLine("我正在路上行驶……");
- }
- public void Run(string RoadName)
- {
- Console.WriteLine("我正在" + RoadName + "公路上行驶……");
- }
- public void Run(int Mileage)
- {
- Console.WriteLine("我已经行驶了" + Mileage + "公里……");
- }
- }
- class Class_03_05
- {
- public static void Main(String[] args)
- {
- Car car1 = new Car();
- Car car2 = new Car("Blue", 1.5F);
- Console.WriteLine("car1的颜色是" + car1.color);
- Console.WriteLine("car2的颜色是" + car2.color);
- car1.Run();
- car1.Run("51号");
- car1.Run(100);
- }
- }
- }