Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Java | Functions | Question 4

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article




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

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


Answer: (A)

Explanation: Objects are never passed at all. Only references are passed. The values of variables are always primitives or references, never objects

Quiz of this Question

My Personal Notes arrow_drop_up
Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads