菜鸟求救,请问这个程序怎么运行不成?
public class GrandFather {
public GrandFather(){
System.out.println("GrandFather constructor block!");
}
static{
System.out.println("GrandFather static block!");
}
}
public class Father extends GrandFather{
public Father(){
System.out.println("Father constructor block!");
}
static{
System.out.println("Father static block!");
}
}
public class Son extends Father{
public Son(){
System.out.println("Son constructor block!");
}
static{
System.out.println("Son static block!");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Son s = new Son();
}
}
------解决方案--------------------
你如果把这三个类放在同一个文件中,需要把不是主类的那两个public去掉,因为一个文件中只能有一个public公共类;也可以分成三个文件分别存放;