TripCS 2016-05-17 09:56 采纳率: 0%
浏览 1144

java中这两个构造方法一个队,一个错?感觉没有区别啊?

第一种:
public class point {
private double x;
private double y;
public point(){
this(0,0);
}
public point(double x, double y){
this.x = x;
this.y = y;
}
}
第二种
public class point {
private double x;
private double y;
public point(){
this.x = this.y = 0;
}
public point(double x, double y){
if(x > 0||y > 0){
this.x = x;
this.y = y;
}else{
this();
}
}

  • 写回答

3条回答

  • 毕小宝 博客专家认证 2016-05-17 10:02
    关注

    很简单,第二种写法有编译错误Constructor call must be the first statement in a constructor。
    java语法归档,调用构造函数必须是第一条语句,你这样显然是不行的。

    评论

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题