我有这样的要求
/*
* 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???
/*
* 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???
* @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; }
}