class Point
    {
        public double x, y;
        public Point()
        {
            this.x = 0;
            this.y = 0;
        }        public Point(double x, double y)
        {
            this.x = x;
            this.y = y;
        }        public  static double Distance(Point a, Point b)
        {
            double xdf = a.x - b.y;
            double ydf = a.y - b.y;
            return Math.Sqrt(xdf*xdf+ydf*ydf);
        }
请问一下上面这段代码里的是什么意思:
 public Point()
        {
            this.x = 0;
            this.y = 0;
        }        public Point(double x, double y)
        {
            this.x = x;
            this.y = y;
        }
麻烦大家给我解释一下,我是初学.

解决方案 »

  1.   

    new这个类的时候自动执行Point这个函数至于执行那个,根据你new的时候的参数来顶Point a = new Point() 就执行上面这个
    Point a = new Point(1,2) 就执行下面这个
      

  2.   


            public Point() 
            { 
                this.x = 0; //让类的成员标量x=0
                this.y = 0; //让类的成员标量y=0
            }         public Point(double x, double y) 
            { 
                this.x = x; //让类的成员标量x等于传入的参数double x
                this.y = y; //让类的成员标量y等于传入的参数double y        } 
      

  3.   

    我是否可以这样理解?:
    public Point()  //这个是无参方法 
            { 
                this.x = 0; 
                this.y = 0; 
            }         public Point(double x, double y) //这个是有参方法
            { 
                this.x = x; 
                this.y = y; 
            } 
      

  4.   


    大致是这样Point point1=new Point();
    调用第一个Point point2=new Point(3.0,5.0);
    实例化对象时调用第二个一个是有参数,一个是无参数无参数的是默认的构造方法,根据需要选择