1 代码
public class ParamCopyTest {
public static void main (String [] args){
System.out .println("hello!" );
int m = 5 ;
System.out .println("m:" +m);
double_num(m);
System.out .println("m:" +m);
Employ e = new Employ("e" );
e.set_num(5 );
System.out .println(e.getM());
double_class_private_num(e);
System.out .println(e.getM());
Employ e1 = new Employ("e1" );
Employ e2 = new Employ("e2" );
System.out .println(e1.getName());
System.out .println(e2.getName());
swap(e1,e2);
System.out .println(e1.getName());
System.out .println(e2.getName());
}
public static void swap (Employ a,Employ b)
{
Employ temp = a;
a = b;
b = a;
}
public static void double_num (int x)
{
x = x*2 ;
}
public static void double_class_private_num (Employ e)
{
e.double_num();
}
}
class Employ
{
private int m;
private String name;
public Employ (String name)
{
this .name = name;
}
public String getName ()
{
return this .name;
}
public void double_num ()
{
m = m*2 ;
}
public void set_num (int value )
{
this .m = value ;
}
public int getM ()
{
return m;
}
}
2 结果
➜ ParamTest javac ParamCopyTest.java
➜ ParamTest java ParamCopyTest
hello!
m: 5
m: 5
5
10
e1
e2
e1
e2