In this example, MyInnerClass is an inner class of MyOuterClass.
It is
not a subclass of MyOuterClass.
As stated in the
Java Tutorial:
an inner class is associated with an instance of its enclosing class and has direct access to that object's methods and fields.
That is why the second code example, where MyInnerClass directly uses sayHai() from MyOuterClass is possible.
Because MyInnerClass is an inner class, not a subclass, of MyOuterClass, you cannot access sayHai() via an instance of MyInnerClass. MyInnerClass doesn't inherit the methods of MyOuterClass because it does not extend MyOuterClass.
An inner class and a subclass (class that extends) are different things.
[ May 27, 2008: Message edited by: Stevi Deter ]