Saturday, May 11, 2019

what will be the output of thread problem?

Problem statement:
what will be the output of the following code?
  1. public class Person extends Thread {
  2.     private int count;
  3.     private Person(int count) {
  4.         this.count = count;
  5.     }
  6.     @Override
  7.     public void run() {
  8.         for (int i = 1; i < 4; i++) {
  9.             count = count + 1;
  10.         }
  11.     }
  12.     public static void main(String[] args) {
  13.         Person t = new Person(10);
  14.         t.start();
  15.         System.out.println(t.count);
  16.     }
  17. }
Output: 10
output will vary, will explain the reason soon

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...