本帖最后由 igi9009 于 2014-4-23 17:22 编辑
问题有好几个:主函数必须写全,还有就是建立内部对象写错了,应该写成China china=new China();
China.Beijing bj=china.new Beijing();
bj.speak();帮你做了点修改就能运行了,正确程序如下- class China
- { final String nationalAnthem="义勇军进行曲";
- //Beijing beijing;
- public China()
- { China.Beijing beijing=new Beijing();
- }
- public String getSong()
- { return nationalAnthem;
- }
- public class Beijing
- { String name="北京";
- void speak()
- { System.out.println("我们是"+name+" 我们的国歌是:"+getSong());
- }
- }
- }
- public class InnerTest1
- {
- public static void main(String[] args)
- {
- China china=new China();
- China.Beijing bj=china.new Beijing();
- bj.speak();
- }
- }
复制代码 |