package com.interview; public class Threading { int counter; class Mythread extends Thread{ @Override public void run(){ for(int i=0; i < 10000; i++) counter++; System.out.println("run = " + counter); } } public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub Threading a = new Threading(); Mythread t1 = a.new Mythread(); t1.start(); t1.join(); System.out.println("" + a.counter); } }
Sigiloso
Will be printed next : run = 10000 10000 Program starts the thread and waits while it will be died. Next prints a.counter value