这是我在Notepad++上打得代码。。。
public class Transport { public void manned() { System.out.println("Transport can Manned"); } } public class Bus extends Transport { public void manned() { System.out.println("Bus = 40"); } } public class Ship extends Transport { public void manned() { System.out.println("Ship = 200"); } } public class Plane extends Transport { public void manned() { System.out.println("Plane = XXX"); } } public class Initail { public static void main(String[] args) { Transport bus = new Bus(); Transport ship = new Ship(); Transport plane = new Plane(); bus.manned(); ship.manned(); plane.manned(); } }
在CMD中编译出现:
H:\>javac Transport\Initail.java
Transport\Initail.java:1: 错误: 类 Transport 是公共的, 应在名为 Transport.java 的文件中声明
public class Transport {
^
Transport\Initail.java:7: 错误: 类 Bus 是公共的, 应在名为 Bus.java 的文件中声明
public class Bus extends Transport {
^
Transport\Initail.java:13: 错误: 类 Ship 是公共的, 应在名为 Ship.java 的文件中声明
public class Ship extends Transport {
^
Transport\Initail.java:19: 错误: 类 Plane 是公共的, 应在名为 Plane.java 的文件中声明
public class Plane extends Transport {
^
请教一下各位!!!感谢!
如果你是把这段全部都写在同一个类文件的话,就只能有一个类前面写public。你把其他类前面的修饰符public删了应该就好了