Topic: static 方法如何调用类中的其他方法和变量

  Print this page

1.static 方法如何调用类中的其他方法和变量 Copy to clipboard
Posted by: leiofll
Posted on: 2005-06-25 11:40

今天编程发现一般的main方法都是static , 但是我想要在main中调用其他方法(例如change())就也得把别的方法定义成static(public static void change() ),但是这样后,我在其他方法中调用这个类的实例变量总会提示::非静态变量不能被静态方法调用 , 我要怎么做才可以解决这个问题呢

2.Re:static 方法如何调用类中的其他方法和变量 [Re: leiofll] Copy to clipboard
Posted by: MountLion
Posted on: 2005-06-25 14:29

class A{
...
public static void main(...){
A a= new A();
a.change();
}
}

3.Re:static 方法如何调用类中的其他方法和变量 [Re: leiofll] Copy to clipboard
Posted by: 2352439
Posted on: 2005-06-25 14:35

静态方法调用非静态方法:

先创建对象后再调用

4.Re:static 方法如何调用类中的其他方法和变量 [Re: leiofll] Copy to clipboard
Posted by: leiofll
Posted on: 2005-06-25 19:08


今天下午测试了
可以
谢谢


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923