What will be the result of the following code execution?

class A { 
    private int counter = 0; 
    public static int getInstanceCount() {
        return counter;
    } 
    public A() {
        counter++;
    }
}
public class B {
    public static void main(String ar[]) {
        A a1 = new A();
        A a2 = new A();
        A a3 = new A();
        System.out.println(A.getInstanceCount()); //1
    }
}   

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes