Menu
Topics Index
...
`

Method Overriding1988


If you need explanation Read this topic

If you need Answer Take test on this topic

Method Overriding1988
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-");
        }
    }
}

A. -Inner2--Inner1--Main--Inner2--Inner1-
B. -Inner2--Main--Inner1--Main--Main--Inner2--Main--Inner1--Main-
C. Some other output
D. Compilation Error or Runtime Error
Topic: Advanced Java Programming Concepts

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans a.depends on the func cal sop gets printd

Posted by Maheshwari Natarajan    2014-08-04 12:32:58


D.compilation error hppns as v r trying inner1 i1=new Inner1() non static variable cannot b acced from static content.

Posted by Shabaaz Shaikz    2014-08-04 12:33:56


a...as one by one each functn objct is cald n respctvly stmnt is prntd

Posted by Asma Mujtaba Khan    2014-08-04 13:09:03


d.
compilation err.
no enclosin variabl of outer class accessd

Posted by NagaRaj Nataraj    2014-08-04 14:05:58


Congratulations Shabaaz Shaikz. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-05 04:50:14


© meritcampus 2019

All Rights Reserved.

Open In App