publicclassValueTransfer{voidmodify(inti){i++;}voidmodify(int[]arr){for(inti=0;i
public class ValueTransfer {
void
modify(int i) {
i++; }
void
modify(int[] arr) {
for
(int i = 0; i < arr.length; i++) {
arr[i]
= 1; } }
void
modify(SimpleClass simpleClass) {
simpleClass.field
= 1; }
public
static void main(String[] args) {
ValueTransfer
valueTransfer = new ValueTransfer();
int
intValue = 0;
valueTransfer.modify(intValue);
System.out.println("intValue
= " + intValue);
int[]
intArr = new int[1];
intArr[0]
= 100;
valueTransfer.modify(intArr);
System.out.println("intArr[0]
= " + intArr[0]);
SimpleClass
simple = new SimpleClass();
valueTransfer.modify(simple);
System.out.println("simple.field
= " + simple.field); }}
class SimpleClass {
int
field;}
展开