public class Ex24PassString { public static void main(String[] args) { //example to show, although string is pass by reference, it cannot be changed due to the fact that string object is immutable in java String name = "Shakesphere"; System.out.println("In main, the name is "+name); changeName(name); System.out.println("Back in main, the name is "+name); } public static void changeName(String str) { str = "Dickens"; //String object is immutable, cannot be changed System.out.println("In changeName, the name is now "+str); } }