I was learning Threads , and I'm stuck up on this program, why is this resulting in NPE? why do the threads not run?
here's my code:
class Chicks {
synchronized void yack(long id) {
for(int x = 1; x < 3; x++) {
System.out.print(id + " ");
Thread.yield();
}
}
}
class ChicksYack implements Runnable {
Chicks c;
public static void main(String[] args) {
new ChicksYack().go();
}
void go() {
c = new Chicks();
new Thread(new ChicksYack()).start();
new Thread(new ChicksYack()).start();
}
public void run() {
c.yack(Thread.currentThread().getId());
}
}