以前看到“如果没有给类提供构造函数,则编译器会自动提供一个默认的无参数的构造函数,如果用户提供了自己的构造函数,则编译器就不在提供默认的无参数构造函数”。但是为什么下面的程序可以编译执行,并且没有警告,错误或者异常抛出?好像即使我给出了自己的构造函数,java编译器仍然提供一个无参数的构造函数? 我用的是java1.6,谁能给个解释?
public class ClassTest
{
public static void main(String[] args)
{
Point pt1 = new Point();
pt1.output();
}
}class Point
{
void Point(int x, int y)
{
this.x = x;
this.y = y;
}

int x, y;
void output()
{
System.out.println( "x = "+ x+ ", y = "+y );
}
}

解决方案 »

  1.   

    sorry,主题应该是"Java类中构造函数的问题", 和继承没有关系!
      

  2.   

    void Point(int x, int y){}不是构造函数构造函数没有返回值,应该是Point(int x, int y)去掉void,你再看看!
      

  3.   

    void Point(int x, int y),去掉void
      

  4.   

    void Point(int x,int y) //这个根本不是构造函数啊,构造不能有返回值,void的意思是:有返回值,但是
                               //返回为空

    this.x   =   x; 
    this.y   =   y;