How come setWav doesn't change the wav in wav + " " + "Grapes"? Do I have to create a set method for add if I want it to output Oranges? Grapes?
EDIT: Thanks everyone for the help, much appreciated.
package javaapplication1;
public class JavaApplication1 {
public static void main(String[] args)
{
NewClass object1 = new NewClass();
System.out.println(object1.getAdd());
object1.setWav("Oranges?");
System.out.println(object1.getAdd());
}
}
OUTPUT:
Burgers Grapes
Burgers Grapes
package javaapplication1;
public class NewClass
{
private String wav;
private String add;
public NewClass()
{
wav = "Burgers";
add = wav + " " + "Grapes";
}
public void setWav(String wav)
{
this.wav = wav;
}
public String getWav()
{
return wav;
}
public String getAdd()
{
return add;
}
}