日期:2014-05-20  浏览次数:20899 次

请问这个在ECLIPSE上运行为什么提示找不到main函数
import static org.greggordon.tools.Print.*;
public class C {
class Cycle {
private String name = "Cycle";
public static void travel(Cycle c) {
println("Cycle.ride() " + c);
}
public String toString() {
return this.name;
}
}

class Unicycle extends Cycle {
private String name = "Unicycle";
public String toString() {
return this.name;
}
}

class Bicycle extends Cycle {
private String name = "Bicycle";
public String toString() {
return this.name;
}

}

class Tricycle extends Cycle {
private String name = "Tricycle";
public String toString() {
return this.name;
}
}

public class Biking {
public static void ride(Cycle c) {
c.travel(c);
}
public static void main(String[] args) {
Unicycle u = new Unicycle();
Bicycle b = new Bicycle();
Tricycle t = new Tricycle();
ride(u);
ride(b);
ride(t);
}
}

}
而且没有红线代码!

------解决方案--------------------
内部类里面不能有静态方法,你的程序在编译的时候就会报错
------解决方案--------------------
public static void travel(Cycle c) 不应该申明为static 

如果需要static 看你的调用 应该把方法放在主类里面

你的main方法属于Cycle 而不是外部的C

println 改为 System.out.println