Inner Classes and Enclosing Instances in java?
While reading java Doc i got following things .
So if I write
public class O{
class Inner1{
//
}
class Inner2{
}
}
My Question is out of these two Inner class which one is the direct Inner Class of O ?
And there are also some points which I got there.
2.A class O is the n'th lexically enclosing class of a class C if it is the immediately enclosing class of the n-1'th lexically enclosing class of C.
3.An instance i of a direct inner class C of a class O is associated with an instance of O, known as the immediately enclosing instance of i. The immediately enclosing instance of an object, if any, is determined when the object is created.
4.An object o is the zeroth lexically enclosing instance of itself.
5.An object o is the n'th lexically enclosing instance of an instance i if it is the immediately enclosing instance of the n-1'th lexically enclosing instance of i.
6.An instance of an inner class I whose declaration occurs in a static context has no lexically enclosing instances. However, if I is immediately declared within a static method or static initializer then I does have an enclosing block, which is the innermost block statement lexically enclosing the declaration of I.
7.For every superclass S of C which is itself a direct inner class of a class SO, there is an instance of SO associated with i, known as the immediately enclosing instance of i with respect to S. The immediately enclosing instance of an object with respect to its class' direct superclass, if any, is determined when the superclass constructor is invoked via an explicit constructor invocation statement.
8.When an inner class (whose declaration does not occur in a static context) refers to an instance variable that is a member of a lexically enclosing class, the variable of the corresponding lexically enclosing instance is used.
Please Explain me these things in simple term as its already seems very confusing while reading these
They both are since O
is the immediately lexically enclosing class of both Inner1
and Inner2
.
Note the " a "
An inner class C is a direct inner class of a class O if O is the immediately lexically enclosing class of C and the declaration of C does not occur in a static context
There isn't necessarily a single one. There can be many.
链接地址: http://www.djcxy.com/p/91992.html上一篇: 静态嵌套类可以访问外部类的私有构造函数
下一篇: java中的内部类和外壳实例