- class Person
- {
- public static void speak()
- {
- System.out.println("speak chinese");
- }
- }
- class PersonDemo
- {
- //Person p= new Person();
- public static void main(String[] args)
- {
- Person p= new Person();
- p.speak();
- }
- }
复制代码 这样运行是没问题的,可是把Person对象移到主函数外为什么运行不成功?
- class Person
- {
- public static void speak()
- {
- System.out.println("speak chinese");
- }
- }
- class PersonDemo
- {
- Person p= new Person();
- public static void main(String[] args)
- {
- //Person p= new Person();
- p.speak();
- }
- }
复制代码
|
|