Answers for "pass by reference in java"

0

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++;  
    }
}
Posted by: Guest on July-26-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language