// 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
}
}
The code is showing an error on static void f(Number k)
. Should I put the method void f()
in a class? If yes, why is that necessary?