public class Hero{
private String name;
private int life;
public Hero(String name,int n){
this.name=name;
life=n;
}
public void printInfo(){
System.out.println(name);
System.out.println("life="+life);
}
public class Democonstructor{
public static void main(String[] s){
Hero hr=new Hero("tangyong",500);
hr.printInfo();
}
}
}
它说E:\study>javac Hero.java
Hero.java:13: 内部类不能有静态声明
public static void main(String[] s){
我要怎么改啊
參考答案:public class Hero{
private String name;
private int life;
public Hero(String name,int n){
this.name=name;
life=n;
}
public void printInfo(){
System.out.println(name);
System.out.println("life="+life);
}
public static void main(String[] s){
Hero hr=new Hero("tangyong",500);
hr.printInfo();
}