Base关键字

父类的构造方法 在 子类的构造方法 之前调用

父类如果是无参构造方法则子类构造方法可以不写     :base()

namespace ConsoleApplication2.面向对象
{    
    class Plane
    {
        protected float width;
        protected float height;
        public float x;
        public float y;
        protected string bgImage;
        protected float speed;

        protected int hp;


        public Plane(float width,float height,float x,float y,string bgImage,float speed) {
            this.width = width;
            this.height = height;
            this.x = x;
            this.y = y;
           
            this.bgImage = bgImage;
            this.speed = speed;
        }
      
        class MyPlane : Plane {
         public MyPlane(float w,float h,float x,float y,string bgimg,float s):base(w,h,x,y,bgimg,s)
        {
                 hp=1;
        }
  }

猜你喜欢

转载自blog.csdn.net/qq_36499416/article/details/80914263