adplus-dvertising
frame-decoration

Question

Which statement, if placed in a class other than MyOuter or MyInner, instantiates an instance of the nested class?
public class MyOuter 
{
    public static class MyInner 
    {
        public static void foo() { }
    }
}

a.

MyOuter.MyInner m = new MyOuter.MyInner();

b.

MyOuter.MyInner mi = new MyInner();

c.

MyOuter m = new MyOuter();
MyOuter.MyInner mi = m.new MyOuter.MyInner();

d.

MyInner mi = new MyOuter.MyInner();

Posted under Java Programming

Answer: (a).MyOuter.MyInner m = new MyOuter.MyInner();

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Which statement, if placed in a class other than MyOuter or MyInner, instantiates an instance of the nested class?