Pass by Reference

Pass by Reference

Pass by Reference — Means the method receives a copy of the reference, pointing to the same object.

Public class PassByReferenceArrayExample {
    public static void main(String[] args) {
        int[] numbers = {1, 2, 3};
        modifyArray(numbers);
        System.out.println("After modifyArray: " + numbers[0]); // Outputs: 10
    }

    public static void modifyArray(int[] arr) {
        arr[0] = 10;
    }
}

Related concepts

Pass by Reference

Pass by Reference — Structure map

Clickable & Draggable!

Pass by Reference — Related pages: