class Param implements Runnable {
int c;
public Param(int a, int b){
c = a+b;
}
public void run(){
// System.out.println(a); // <<<<----What I'm going to do. it's impossible.
}
}
public class ParamTest {
public static void main(String args[]){
Runnable r = new ThreadParam(10,20);
new Thread(r).start();
}
}
In above code, How can I print the value of "a"? My goal is, when I call Runnable r = new ThreadParam(10,20)
in main method, I want to print value of "a" --> 10
. Is this impossible? If I declare int a
into run() method, the result of "a" is '0'. I want to the result "10". How can I do that?