A

Admin • 828.03K Points
Coach

Q. What will be the output?
public class Test{
public static void main(String[] args){
String value = "abc";
changeValue(value);
System.out.println(value);
}

public static void changeValue(String a){
a = "xyz";
}
}

  • (A) abc
  • (B) xyz
  • (C) Compilation fails
  • (D) Compilation fails D. Compilation clean but no output
  • Correct Answer - Option(A)
  • Views: 6
  • Filed under category Java
  • Hashtags:

Explanation by: Admin
Java pass reference as value. passing the object reference, and not the actual object itself. Simply reassigning to the parameter used to pass the value into the method will do nothing, because the parameter is essentially a local variable.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.