Menu
Question Index
...

What will be the output of the following program?

public class Increment
{
    public static void main(String[] args)
    {
        A a = new A(5);
        a.increment();
        a.operate();
        a = new A(a.i);
        a.operate();
        a.increment();
        System.out.println("i = " + a.i);
    }
}

class A
{
    int i = 0;

    A(int i)
    {
        this.i = i + 4;
    }

    void increment()
    {
        i = this.i + 1;
    }

    void operate()
    {
        i *= 3;
    }
}


i = 1
i = 103
i = 55
Compilation Error

Doubts

Problems

Topic: Java Multiple Methods In One Class

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App