Menu
Question Index
...

What will be the output of the following program?

class Increment
{
    public static void main(String[] args)
    {
        Simple s = new Simple();
        Simple r = new Simple();

        s.incr();
        r.incr();

        s.display();
        r.display();
    }
}
class Simple
{
    static int a = 5;
    void incr()
    {
        a++;
    }

    void display()
    {
        System.out.println("a = " + a);
    }
}


a = 5
a = 5
a = 6
a = 6
a = 7
a = 7
Compilation Error
Runtime Error

Doubts

Problems

Topic: Static Keyword 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