It's called a "qualified superclass constructor invocation.
It's called a "qualified superclass constructor invocation". Citing from here: Explicit constructor invocation statements can be divided into two kinds: Alternate constructor invocations begin with the keyword this (possibly prefaced with explicit type arguments). They are used to invoke an alternate constructor of the same class.
Superclass constructor invocations begin with either the keyword super (possibly prefaced with explicit type arguments) or a Primary expression. They are used to invoke a constructor of the direct superclass. Superclass constructor invocations may be further subdivided: Unqualified superclass constructor invocations begin with the keyword super (possibly prefaced with explicit type arguments).
Qualified superclass constructor invocations begin with a Primary expression . They allow a subclass constructor to explicitly specify the newly created object's immediately enclosing instance with respect to the direct superclass (§8.1.3). This may be necessary when the superclass is an inner class.
Inner Classes (non-static child classes) are essentially Nested Classes (static child classes) with implicit links back to their parent objects. Here is your above code, written instead using a static nested class: class Outer { static class Inner { final Outer parent; Inner(Outer _parent) { parent = _parent; System.out. Println("Inner"); } } } public class Child extends Outer.
Inner { Child(Outer o) { super(o); // o.super(); System.out. Println("Child"); } public static void main(String args) { new Child(new Outer()); } } Looking at this, you should be able to understand what o.super() was doing.
2 In fact, a non-static inner class is essentially syntactic sugar for the above, by my understanding. – Luke Maurer May 14 '10 at 2:42 No, a nested static class is essentially a outer level class, which is there just for packaging convenience. – Adeel Ansari May 14 '10 at 2:51 Well, right.
I just mean a non-static inner class is syntactic sugar on top of syntactic sugar :-D – Luke Maurer May 14 '10 at 2:55.
To a particular object. It's sorta like each one gets its own version of the class, much like a non-static field or method belongs to a particular object. So that's why we have funny syntax like instance.
New Inner() and instance.super() — for contexts where the answer to the question “but whose Inner? €? Isn't immediately obvious.
(In a non-static method of the outer class, you can just say new Inner(), and as usual that's short for this. New Inner(). ).
Why does o.super() in Child ends up invoking Outer. Inner constructor? It's simple: because Child extends Outer.
Inner, and constructor calls are always chained up the hierarchy. Here's a slight expansion to your snippet to illustrate: class Outer { Outer() { System.out. Println("Outer"); } void outerMethod() { } class Inner { Inner() { System.out.
Println("OuterInner"); outerMethod(); } String wealth; } } class OuterChild extends Outer { OuterChild() { System.out. Println("OuterChild"); } } public class OuterInnerChild extends Outer. Inner { OuterInnerChild(Outer o) { o.super(); System.out.
Println("OuterInnerChild"); this. Wealth = "ONE MILLION DOLLAR! "; } public static void main(String args) { System.out.
Println(new OuterInnerChild(new Outer()). Wealth); new OuterChild(); } } This prints: Outer OuterInner OuterInnerChild ONE MILLION DOLLAR! Outer OuterChild Some key observations: Because OuterInnerChild extends Outer.
Inner, it inherits wealth, just like normal subclass semantics And just like normal subclass semantics, the constructor of OuterInnerChild chains to the constructor of Outer. Inner Because OuterChild extends Outer, its constructor chains, even when not invoked explicitly Whether implicitly or explicitly, the constructor chains up the hierarchy But why does the compiler demand that OuterInnerChild constructor takes an Outer o, and that o.super() is invoked? Now that is specific to inner class semantics: it's done to ensure that all instances of OuterInnerChild has an enclosing Outer instance for Outer.
Inner, the super class of OuterInnerChild. Otherwise, the constructor of Outer. Inner would not have an enclosing instance of Outer to invoke outerMethod() on.
Always not to forget basic principles, in process of calling a sub class constructor it's always the parent class is instantiated first irrespective of inner/outer classes. In your scenario, as you are extending inner class and your inner class is a member of parent class which needs to be instantiated then followed by calling the actual inner class constructor.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.