构造函数出现问题!
import java.util.*;public class Gnome{
public String name;
public int age;
public Gnome gnome_buddy;
private boolean magical= false;
public double height = 2.6;
public static final int MAX_HEIGHT = 3;
Gnome(String nm , int ag , Gnome bud, double hgt){
name = nm;
age = ag;
gnome_buddy = bud;
height = hgt;
}
Gnome(){
name ="Runmple";
age =204;
gnome_buddy = null;
height = 2.1;
}
public static void makeKing(Gnome h){
h.name = "King" + h.getRealName();
// h.magical = ture;
}
public void makeMeKing(){
name = "King" +getRealName();
// magical= ture;
}
public boolean isMagical(){
return magical;
}
public void setHeight(){
// height= newHeight;
}
public String getName(){
return "I won't tell!";
}
public String getRealName(){
return name;
}
public void renameGnome(String s ){
name = s;
}
}
class Test{
public static void main(String args[]){
Scanner i = new Scanner(System.in);
Gnome g = new Gnome();
System.out.println("Enter the name");
g.age = i.nextInt();
System.out.println(g.age);
}
}
只有注释掉一下东西才能运行,但是本来代码是有的,但是为什么会错呢!