很简单的java程序编译出错?有高手吗


public class Frog {

static int frog = 0;
public Frog(Frog frog2){
frog += 1;
}

public static void main(String[] args){
new Frog;
new Frog;
new Frog;
System.out.println(;
}



}

Java中的对象的初始化 应该为 对象 name = new 对象(……),
其中()类的参数是根据你类的设计而定的,如果你的类中有无参的构造函数,或者没有显示的给出构造函数 者可以写成 对象 name = new 对象(),
你问题中的程序已经有了一个构造函数
[code="java"]
public Frog(Frog frog2){
frog += 1;
}
[/code]

所以在创建这个对象的时候应该传一个Frog对象(例如上面rabby 回答中 传进一个null)
希望对你有帮助.

错在构造方法没带参数吧 :)

public class Frog {

static int frog = 0;

public Frog(Frog frog2) {
    frog += 1;
}

public static void main(String[] args) {
    new Frog(null);
    new Frog(null);
    new Frog(null);
    System.out.println(Frog.frog);
}

}

楼主先买本入门书好好看看吧

public class Frog {

static int frog = 0;
public Frog(){
frog += 1;
}

public static void main(String[] args){
new Frog();
new Frog();
new Frog();
System.out.println(frog );
}

}