The Wayback Machine - https://web.archive.org/web/20210514105356/https://www.geeksforgeeks.org/java-functions-question-2/
Skip to content
Related Articles

Related Articles

Java | Functions | Question 2
  • Last Updated : 07 Jan, 2014




public class Main { 
    public static void main(String args[]) { 
       String x = null; 
       giveMeAString(x); 
       System.out.println(x); 
    } 
    static void giveMeAString(String y) 
    { 
       y = "GeeksQuiz"; 
    } 
}

(A) GeeksQuiz
(B) null
(C) Compiler Error
(D) Exception


Answer: (B)

Explanation: Parameters in Java is passed by value. So the changes made to y do not reflect in main().

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :