πŸ“Š JAVA
Q. What will be the output?
Code:
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 failsD.Compilation clean but no output
πŸ’¬ Discuss
βœ… Correct Answer: (A) abc

Explanation: 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.

Explanation by: Pooja
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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
66
Total Visits
πŸ“½οΈ
12 mo ago
Published
πŸŽ–οΈ
Pooja
Publisher
πŸ“ˆ
86%
Success Rate