Last Updated :
10 Apr, 2024
class GFG
{
int a = 1;
int b = 3;
GFG func(GFG obj)
{
GFG obj3 = new GFG();
obj3 = obj;
obj3.a = obj.a++ + --obj.b;
obj.b = obj.b;
return obj3;
}
public static void main(String[] args)
{
GFG obj1 = new GFG();
GFG obj2 = obj1.func(obj1);
System.out.println(\"obj1.a = \" + obj1.a + \" obj1.b = \" + obj1.b);
System.out.println(\"obj2.a = \" + obj2.a + \" obj2.b = \" + obj2.b);
}
}
Predict the correct option for the above program
(A) obj1.a = 3 obj1.b = 2
obj2.a = 3 obj2.b = 2
(B) obj1.a = 1 obj1.b = 3
obj2.a = 3 obj2.b = 2
(C) obj1.a = 3 obj1.b = 2
obj2.a = 1 obj2.b = 3
(D) Compilation error
Answer: (A)
Explanation:
obj1 and obj2 refer to same memory address.
Share your thoughts in the comments
Please Login to comment...