Hi i dont know if this question has already been asked before but this is getting really annoying...
Ok so i have a class called Test:
public class Test {
public static Test testObject = new Test(5);//Creates a test object with an initialized value of 5;
int number;
public Test(int number){
this.number = number;
}
}
And of course my main class...
public class Main {
public static void main(String args[]){
Test anotherObject = Test.testObject;//this is not a reference right?
System.out.println(Test.testObject.number);//This prints 5
anotherObject.number = 50;// changing anotherObject's number. NOT testObject's Number.
System.out.println(Test.testObject.number);//if that was true this whould of still been 5, but it prints 50!!?? why does testObject's number even change if im not even changing that value?
}
}
if there is something im doing wrong please let me know, thank you very much!!