Menu
Question Index
...

What will be the output of the following program?

class variables
{
    int a;
    static int b;
        variables()
        {
            b++;
        }
        public void showData()
        {
            System.out.println(a + " " + b);
        }
}
class variablesTesting
{
    public static void main(String args[])
    {
        variables s1 = new variables();
        s1.showData();
        variables s2 = new variables();
        s2.showData();
        variables.b++;
    }
}


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

Doubts

Problems

Topic: Static and Non Static Variables - Static and Non Static Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App