Greetings to all experts,
I am a newbie here in Java OOP and is struggling in practicing how to code a OO program, using Java. I hope anyone can give me a head start to enable me to write the main method to test the 2 methods.
Here's the question:
The following two methods changeName1 and changeName2 attempt to update the value of the variable name. Write a main method to test which of them successfully does its task. Explain the result.
public class Human {
String name;
public void setName(String string) {name = string;}
public String getName() {return name;}
static void changeName1(Human in,String newName) {
Human another = new Human();
in = another;
in.setName(newName);
}
static void changeName2(Human in,String newName) {
in.setName(newName);
}
}
Thank you so much.