Created
October 24, 2018 18:04
-
-
Save finnkvan/972838071334663339703b6ca4900b72 to your computer and use it in GitHub Desktop.
Interview Question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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