LogiQuest
Back to Inner Classes
10

What is the output of the following program?

public class Main {
    int x = 1;
    class Inner {
        int x = 2;
        int sum() { return x + Main.this.x; }
    }
    public static void main(String[] args) {
        System.out.println(new Main().new Inner().sum());
    }
}
Hard

Discussion (0)

  • No discussion yet. Ask a doubt or share a shortcut.

Log in to join the discussion.