I want to know how or if I can set multiple Class fields using one or several Class methods which don't specifically refer to any field?. I made the simplest example I could think of.
My apologies if this is a terribly obvious question which has been answered. I found a couple of questions that seemed similar but they involved several classes and were confusing. I think having this question is beneficial and might be easy for someone to answer.
public class MyClass {
private String str = "hello";
private String str2 = "ciao";
private String str3 = "hola";
public void changeSomeString(){
changeString(str);
}
private void changeString(String s){
s = "goodbye";
}
public void changeSpecificString(){
str = "goodbye";
}
public void printString(){
System.out.println(str);
}
public static void main(String args[]) {
MyClass a = new MyClass();
a.printString();
a.changeSomeString();
a.printString();
a.changeSpecificString();
a.printString();
}
}
I can't say I expected, but I wanted
hello
goodbye
goodbye
and I received
hello
hello
goodbye