凑个热门
public class Aaaaa{
public static void main(String args[]){
new Aaaaa().test();
}
public void test(){
A a = new A();
B b = new B();
b.doSomeLogic(a);
System.out.println("a.a="+a.getA());
}
}
class A{
private int a=0;
public int getA(){
return this.a;
}
public void setA(int a){
this.a = a;
}
}
class B{
public void doSomeLogic(A a){
int newValue = new java.util.Random().nextInt(10);
System.out.println("the oldValue="+a.getA());
System.out.println("the newValue="+newValue);
a.setA( newValue );
}
}
public class Test{
public static int sum =1;
}
public class Test2{
public int getSum(int s){
Test.sum = s;
}
}
public class one{
public static int a=1;
}
public class two{
public void two(){
one.a=2;
}
}
没试过不知道行不行,大概意思是这样的,具体怎么写看你自己了
第一个类返回值,第二个类用返回值作参数。
应该是这样吧