Menu
Question Index
...

What will be the output of the following program?

public class Outer {
    public static void main(String[] args) {
        Outer o = new Outer();
        o.side();
        Inner1 i1 = new Inner1();
        i1.side();
    }
    public void side() {
        Inner1 i1 = new Inner1();
        i1.side();
        System.out.print("-Main-");
    }
    public Outer() {
    }
    class Inner1 extends Outer {
        public Inner1() {
            super();
        }
        public void side() {
            Inner2 i2 = new Inner2();
            i2.side();
            System.out.print("-Inner1-");
        }
    }
    public class Inner2 extends Inner1 {
        public Inner2() {
            Outer.this.super();
        }
        public void side() {
            System.out.print("-Inner2-");
        }
    }
}


-Inner2--Inner1--Main--Inner2--Inner1-
-Inner2--Main--Inner1--Main--Main--Inner2--Main--Inner1--Main-
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Advanced Java Programming Concepts

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App