zoukankan      html  css  js  c++  java
  • 第六章 初始继承和多态 上机2

    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();
            }
        }
    }
  • 相关阅读:
    Ajax实现异步上传图片
    python文章的抓取
    python
    Python的MySQLdb模块安装
    import _mysql----ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。
    安装第三方模块时遇到Python version 2.7 required, which was not found
    beautifulSoup安装
    安装setuptools和pip
    python 的简单抓取图片
    python
  • 原文地址:https://www.cnblogs.com/SFHa/p/8795247.html
Copyright © 2011-2022 走看看