public class A implements Runnable{
public static int t;
public void run () {
try {
for (int i = 0; i <= 10000; i++) {
t=i;
this.t = t;
System.out.println(t);
Thread.sleep(10);}
} catch (InterruptedException ex) {
Logger.getLogger(A.class.getName()).log(Level.SEVERE, null, ex);
}
}
public int p(){
return t;
}
}
E em outra classe eu gostaria de usar a mesma variavel:
public class B implements Runnable{
A A= new A();
int t=0;
public void run () {
try {
t=A.p();
while(true){
System.out.println(t);
Thread.sleep(10);}
} catch (InterruptedException ex) {
Logger.getLogger(B.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
A mp= new A();
B mp2= new B();
Thread Mp00 =new Thread(mp);
Thread Mp01 =new Thread(mp2);
Mp00.start();
Mp01.start();