Menu
Question Index
...

What will be the output of the following program?

public class Counter {
    int count = 0;
    Counter() {
        count++;
    }
    public static void main(String srt[]) {
        Counter c1 = new Counter();
        Counter c3 = new Counter();
        Counter c2 = new Counter();
        System.out.print(c1.count + ", ");
        System.out.print(c2.count + ", ");
        System.out.print(c3.count);
    }
}


0, 0, 0
0, 1, 2
1, 1, 1
1, 2, 3
Compilation Error or Runtime Error

Doubts

Problems

Topic: Create Objects Using Constructors In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App