Skip to content

Instantly share code, notes, and snippets.

@finnkvan
Created October 24, 2018 18:04
Show Gist options
  • Select an option

  • Save finnkvan/972838071334663339703b6ca4900b72 to your computer and use it in GitHub Desktop.

Select an option

Save finnkvan/972838071334663339703b6ca4900b72 to your computer and use it in GitHub Desktop.
Interview Question
package com.pivincii;
public class Counter {
private int count = 0;
public void increment() {
count ++;
}
public void decrement() {
count --;
}
public int getCount() {
return count;
}
public static void main(String[] args) {
Counter counter = new Counter();
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
counter.increment();
}
});
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
counter.decrement();
}
});
t1.start();
t2.start();
System.out.println(counter.getCount());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment