Hi,
I wrote these 3 classes to explain my question:
What I want to do is to use the Test class to set the value of the variable n from the Set class, and then use its value from the Use class. If I run this I get an error because the Use class see the value of n as null. How could I use the value of n in all my classes once it's set?
Thank you very much
stack
I wrote these 3 classes to explain my question:
Code:
public class Set {
private BigInteger n;
Random ran = new Random();
public void setN(){
n = new BigInteger(5, ran);
}
public BigInteger getN(){
return n;
}
}
public class Use {
Set set1 = new Set();
public void useN(){
int nLength = set1.getN().toString().length();
}
}
public class Test {
public static void main(String[] args) {
Set set1 = new Set();
Use use1 = new Use();
set1.setN();
use1.useN();
}
}
Thank you very much
stack
Comment