第六章,上机练习1(汽车)


汽车管理

1
using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace No._6 8 { 9 class Program 10 { 11 /// <summary> 12 /// 测试类Main()方法 13 /// </summary> 14 static void Main(string[] args) 15 { 16 Truck truck = new Truck("奥迪A6", "德国"); 17 18 truck.TruckRun(); 19 } 20 } 21 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace No._6
 8 {
 9     public class Truck:Vehicle
10     {
11         /// <summary>
12         /// 结构函数
13         /// </summary>
14         /// <param name="Type"></param>
15         /// <param name="Place"></param>
16         public Truck(string Type, string Place):base(Type,Place)
17         {
18 
19         }
20         /// <summary>
21         /// 输出方法
22         /// </summary>
23         public void TruckRun() 
24         {
25             Console.WriteLine("型号为"+this.Type+",产地为"+this.Place+"的卡车在行驶!");
26         }
27     }
28 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace No._6
 8 {
 9     /// <summary>
10     /// 汽车类
11     /// </summary>
12     public class Vehicle
13     {
14         //型号
15         public string  Type { get; set; }
16         //产地
17         public string Place { get; set; }
18         //构造函数
19         public Vehicle(string type,string place) 
20         {
21             this.Type = type;
22             this.Place = place;
23         }
24     }
25 }
原文地址:https://www.cnblogs.com/yjjh/p/6691732.html