Consider the below Java code:

class Test {
    int i = 1;
    Test increment() {
        i++;
        return this;
    }
    void print() {
        System.out.println("i = " + i);
    }
}

public class Main {
    public static void main(String args[]) {
        Test obj = new Test();
        obj.increment().increment().increment().print();
    }
}

What is the output of the program?

1
The program will throw a runtime error
2
The program will throw a compile-time error
3
i = 1
4
i = 4
5
Question Not Attempted

Sponsored

hivanix.in

Visit

This quiz is brought to you by hivanix.in

🌐 Web App Development

Quick Navigation