What will be the output of the following Java program? class…
What will be the output of the following Java program? class Parent { Parent() { System.out.println(“Parent Constructor Called”); } } class Child extends Parent { Child() { System.out.println(“Child Constructor Called”); } } public class Test { public static void main(String[] args) { Child c = new Child(); } }
Read DetailsWhat will be the output of the following code snippet? class…
What will be the output of the following code snippet? class Counter { private static int count = 0; public static synchronized void increment() { count++; try { Thread.sleep(100); } catch (InterruptedException e) {} } public static int getCount() { return count; } } public static void main(String[] args) throws InterruptedException { Thread t1 = new Thread(new Runnable() { public void run() { for (int i = 0; i < 5; i++) Counter.increment(); } }); Thread t2 = new Thread(new Runnable() { public void run() { for (int i = 0; i < 5; i++) Counter.increment(); } }); t1.start(); t2.start(); t1.join(); t2.join(); System.out.println("Final count: " + Counter.getCount()); } }
Read Details