pass by reference in java
// my class
class my_number {
// public member variable
public int number;
// default constructor
public my_number()
{
number = 1;
}
}
// driver function
class Main{
public static void main (String [] arguments)
{
// creating object
my_number object = new my_number();
// printing before update
System.out.println("number = " + object.number);
// update function called.
update(object);
//printing after update.
System.out.println("number = " + object.number);
}
// update function.
public static void update( my_number obj ){
// increments number variable.
obj.number++;
}
}