KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have studied that java is pass by reference but when I execute following code the strings are not swapped in main method why? static void swap(String s1, String s2){ String temp = s1; s1=s2; s2=temp; } public static void main(String[] args) { String s1 = "Hello", s2 = "world"; swap(s1, s2); System.out.println(s1 + s2); }
Tags (comma-separated)
Save Edits
Cancel