Menu
Question Index
...

What will be the output of the following program?

class Simple
{    
    int a = 0;
    
    void incr()
    {
        a++;
    }
    
    void display()
    {
        System.out.println("a = " + a);
    }
}

class Demo
{
    public static void main(String aRgs[])
    {
        Simple s = new Simple();
        Simple r = new Simple();
        s.incr();
        r.incr();
        s.display();
        r.display();
    }
}


a = 0
a = 0
a = 1
a = 1
a = 0
a = 1
a = 1
a = 2
Compilation Error

Doubts

Problems

Topic: Behavior Of Java Classes Using Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App