码迷,mamicode.com
首页 > 其他好文 > 详细

第六章 上机2

时间:2018-04-12 22:23:13      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:space   linq   类对象   构造函数   bar   name   copy   对象   .text   

技术分享图片
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CarRun
{
    public class Vehicle
    {
        //带参构造函数
        public Vehicle(string place, string type)
        {
            this.Place = place;
            this.Type = type;
        }
        //属性
        public string Place { get; set; }
        public string Type { get; set; }

        //方法
        public void VehicleRun()
        {
            Console.WriteLine("汽车在奔跑");
        }
    }
}
技术分享图片
技术分享图片
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CarRun
{
    class Truck:Vehicle
    {
        //卡车带参构造函数
        public Truck(string place, string type)
            : base(place, type)
        {

        }
        //卡车奔跑的方法
        public void TruckRun()
        {
            Console.WriteLine("型号为{0},产地为{1}的卡车正在行驶",this.Type,base.Place);
        }
    }

}
技术分享图片
技术分享图片
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CarRun
{
    class Program
    {
        static void Main(string[] args)
        {
            //父类对象
            Vehicle v = new Vehicle("中国", "现代");
            v.VehicleRun();

            //子类对象
            Truck truck = new Truck("中国", "红旗");
            truck.TruckRun();//子类方法
            truck.VehicleRun();//父类方法
            Console.ReadLine();
        }
    }
}

第六章 上机2

标签:space   linq   类对象   构造函数   bar   name   copy   对象   .text   

原文地址:https://www.cnblogs.com/wuayn/p/8810272.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!