The Testclass1 class has a variable, some execution is performed that will change the value of the variable. Now in the same package is the class Testclass2. How to access the updated value (updated Testclass1) of a variable in Testclass2. tried it didn't work
Note. Testclass1 and Testclass2 are two separate files in one package, I tried to run class1 first in eclipse and then in class2. But class2 printed 0;
public class Testclass1 {
public static int value;
public static void main(String[]args)
{
Testclass1.value=9;
System.out.println(value);
}
}
----------------
public class Testclass2 {
public static void main(String[]args)
{
System.out.println(Testclass1.value);
}
}
source
share