Java | Functions | Question 3

filter_none

edit
close

play_arrow

link
brightness_4
code

class Test {
public static void swap(Integer i, Integer j) {
      Integer temp = new Integer(i);
      i = j;
      j = temp;
   }
   public static void main(String[] args) {
      Integer i = new Integer(10);
      Integer j = new Integer(20);
      swap(i, j);
      System.out.println("i = " + i + ", j = " + j);
   }
}

chevron_right


(A) i = 10, j = 20
(B) i = 20, j = 10
(C) i = 10, j = 10
(D) i = 20, j = 20


Answer: (A)

Explanation: Parameters are passed by value in Java

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.