I came here because this place seems to have the most knowledgeable programmers on the internet
My question is: In java if everything is essentially an object (aside from primitive data types), including Strings, why do you have to return a String back to main if you want to make some changes to it. example
I know this is a terrible example and I left out details in the code, im just trying to paint a picture here and get the underlying reason as to why that wont work if a String is an object.Code://your main class main { String s = "C programming"; StringChangerObject o = new StringChangerObject(); o.changeString(s); print(s); } //another class in a different file StringChangerObject{ public void changeString(String blah){ blah = "Java programming"; } }
Perhaps maybe that method goes on the stack and since the parameter is on the stack as well, when the method ends, the stack pointer erases all that has to do with that method????
IDK im confuseddddd