I'm not quite sure what to call it, but essentially, when I run this code:
public class test {
static Device one;
static Device two;
public static void main(String[] args) throws Exception {
one = new Device("One", "ONE");
System.out.println(one.getName());
two = new Device("Two", "TWO");
System.out.println(one.getName());
System.out.println(two.getName());
}
}
The output is:
ONE
TWO
TWO
when it should be:
ONE
ONE
TWO
The device object is pretty simple, it just receives two strings, the second being the "name" that I'm asking it to print. I've done OOP before, but I feel like I'm just forgetting some important aspect, but can't seem to figure it out. Any help is appreciated, thanks!
And here is the device constructor:
public Device(String iP, String Name) {
//Set the IP address
IP = iP;
//Set the device's name
name = Name;
// Set the string version of the device (for transmitting)
stringVersion = IP + ";" + name;
}
staticfields. I suggest you use local variables and final non-static fields where possible.