Examveda
Examveda

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 clean but no output

E. None of these

Answer: Option A

Solution(By Examveda Team)

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.


This Question Belongs to Java Program >> Constructors And Methods

Join The Discussion

Related Questions on Constructors and Methods

What is a constructor in Java?

A. A special method to create instances of classes

B. A method used for mathematical calculations

C. A method to perform string manipulations

D. An exception handling mechanism