我编写了以下代码来测试 Java 中类和对象的概念。
public class ShowBike {
private class Bicycle {
public int gear = 0;
public Bicycle(int v) {
gear = v;
}
}
public static void main() {
Bicycle bike = new Bicycle(5);
System.out.println(bike.gear);
}
}
为什么这会在编译过程中给我以下错误?
ShowBike.java:12: non-static variable this cannot be referenced from a static context
Bicycle bike = new Bicycle(5);
^