Hey I'm trying to grasp Threads as a concept. Let me draw you a scenario
class A {
private int counter = 0;
public void add() {
counter++;
}
public int getCounter() {
return counter;
}
}
class B implements Runnable {
public void run() {
A a = new A();
a.add();
a.add();
}
}
class C implements Runnable {
public void run() {
A a = new A();
System.out.println(a.getCounter());
}
}
What does the System.out.println give me when I run C?
I'm guessing it gives me 0 because they each created an instance of A.
If thats true, how would you share that object between the threads?