public class test {
public void main(String args[]) {
int i = 0, j = 0;
System.out.println(i);
System.out.println(j);
}}为什么这样单独执行就执行不了
在void前面加个static就能执行了

解决方案 »

  1.   

    主函数当然要用到静态,建议多用IDE的联想,让他给你生成一个main函数肯定没问题了
      

  2.   

    建议楼主好好看看java 的语法
    public void main(String args[]) 是main方法的一个重载方法
    但是你的类里面没有程序的入口
      

  3.   

    Static methods can be invoked without creating an instance of the containing object.Main method is your program entry point. It is defined to be a static method your class and JVM will invoke this method to start your java program.If your main method is a non-static method, JVM need to create an instance or your class then invoke it, but this is not what JVM is supposed to do.
      

  4.   

    另外  static表识的变量的生命周期是和程序一样长的,当程序一初始化时就驻留在内存,它表识主函数的道理也是这样的
      

  5.   

    ....这个问题...
    just remember,Don't ask why
      

  6.   

    static 的一个重要的用法就是在不创建任何对象的前提下就可以调用它.