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