1=============truck class ==========2 usingSystem;3 usingSystem.Collections.Generic;4 usingSystem.Linq;5 usingSystem.Text;6 usingSystem.Threading.Tasks;7 8 namespacesj1.entity9 {Ten /// <summary> One ///Truck Class A /// </summary> - Public classtruck:vehicle - { the PublicTruck (stringXinghao,stringChandi):Base(Xinghao,chandi) - {} - /// <summary> - ///Truckrun () + /// </summary> - Public voidTruckrun () + { AConsole.WriteLine (string. Format ("The model number is: {0}, the truck where the origin is {1} is driving! ", Xinghao,chandi)); at } - } - -}View Code
1=============vehicle class ==============2 usingSystem;3 usingSystem.Collections.Generic;4 usingSystem.Linq;5 usingSystem.Text;6 usingSystem.Threading.Tasks;7 8 namespacesj1.entity9 {Ten /// <summary> One ///Automobile class A /// </summary> - Public classVehicle - { the Public stringXinghao {Get;Set; }//Model - Public stringChandi {Get;Set; }//Origin - /// <summary> - ///constructor Function + /// </summary> - /// <param name= "Xinghao" ></param> + /// <param name= "Chandi" ></param> A PublicVehicle (stringXinghao,stringChandi) at { - This. Xinghao =Xinghao; - This. Chandi =Chandi; - } - /// <summary> - ///Vehiclrun () method in /// </summary> - Public voidVehiclerun () to { +Console.WriteLine ("the car is driving"); - } the } *}View Code
1============= Test Class ==============2 usingsj1.entity;3 usingSystem;4 usingSystem.Collections.Generic;5 usingSystem.Linq;6 usingSystem.Text;7 usingSystem.Threading.Tasks;8 9 namespaceSJ1Ten { One class Program A { - Static voidMain (string[] args) - { theTruck Truck =NewTruck ("Audi A6","Germany"); - truck. Truckrun (); - truck. Vehiclerun (); - Console.read (); + - } + } A}View Code
Depth. NET platform and C # programming) chapter sixth on-machine Exercise 1. Lixiangyang. 20170411