我有三个班级:一级public class One { private static Two object; public static void set_up(Two object) { int y = object.get(); System.out.println(y); } public static void prn () { System.out.println(object.get()); }} 二班public class Two { private int x; public int get() { return x; } Two(int n){ x = n; } }三班public class Three { public static void main( String[] argv ) { One st = new One(); Two two = new Two(2); st.set_up(two); st.prn(); }}我想改变静态变量object在课堂上Two通过method set_up(Two object)。问题是类中的静态变量与方法中的参数同名。如何修改set_up(Two object)以便将给定参数中的值复制到静态对象?
1 回答
哈士奇WWW
TA贡献1799条经验 获得超6个赞
您可以使用类的名称来限定它:
public static void set_up(Two object) {
One.object = object;
}
添加回答
举报
0/150
提交
取消