我有这样的要求
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package 学习;/**
 *
 * @author Administrator
 */
public class NewMain {    /**
     * @param args the command line arguments
     */
     public static int i=0;
    public static void main(String[] args) {
        // TODO code application logic here
       
        i=5;
        
    }
    public static int geti(){
        System.out.println(i);
        return i;
        
    }
}/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package 学习;/**
 *
 * @author Administrator
 */
public class NewMain1 {    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
       int m=new NewMain().geti();
       System.out.println("m="+m);
    }
}如何在第二个main文件里面得到第一个文件里面对i的修改,是的输出为5???

解决方案 »

  1.   

    一个程序只能运行一个main方法,为什么不将第一个main方法改为普通方法呢?
      

  2.   

    public class Test1 { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    NewMain.i = 5;
    System.out.println(NewMain.geti());
    }}class  NewMain{
    public static int i = 0;

    public static int geti() {
    System.out.println(i);
    return i; }
    }
      

  3.   

    因为一些特殊要求,我确实是需要两个main文件,当然写个函数调用修改i我知道写。