// Simple program to understand pass by reference
import java.util.*;
public class HelloDate {
public static void main(String args[])
{
class Number // Contains only an integer
{
int i;
}
static void f(Number k) // <<--- Illegal start of expression ???
{
k.i = 22;
}
Number n1 = new Number(); // New object of Number
n1.i = 9;
f(n1); //Passing an object
System.out.println(n1.i); // Print
}
}
代码显示错误static void f(Number k)
。我应该把方法void f()
放在一个类中吗?如果是,为什么有必要这样做?