--java Training, Android training, iOS training,. NET training, look forward to communicating with you! ——-
1. Object: is the parent class of all classes, direct or indirect, with the functionality that all objects have.
2, Inner class: will be defined in a variety of other classes inside, the inner class is called the inner class.
▲ access rules for internal classes:
Inner classes can directly access members in external classes, including private.
To access an inner class, an external class must establish an object of the inner class.
Inner classes have direct access to members in external classes because there is a reference to an external class in the inner class, in the form of an external class name.
▲ Access format:
When an inner class is defined on an external class member location, it is not private, and an inner class object can be created directly in the outer other class.
The outer class name. Internal class Name Variable name = External Class object. Inner Class object
Outer.Inner o = new Outer (). New Inner ();
When an inner class is defined on a member position, it can be modified by the member modifier:
? Private: Encapsulates inner classes in the outer class.
? Static: An attribute with static in the inner class.
When an inner class is modified by static, only static members in the outer class can be accessed, with access limitations.
In other external classes, direct access to non-static members of the static inner class:
New. Outer.Inner (). function ();
In other external classes, direct access to non-static members of the static inner class:
Outer.Inner.function ();
Note: When a static member is defined in an inner class, the inner class must be static.
▲ when describing the interior of a city, there is something inside the thing that uses an inner class to describe it because the internal transaction is using external transactions.
The inner class is defined locally and cannot be decorated by the member modifier, and can be accessed directly from the members of the outer class, because it also holds references in the outer class, but cannot access the local variables in which it resides, and can access only the final decorated local variables.
3. Anonymous inner class
The anonymous inner class is actually the shorthand format for the inner class.
Defining an anonymous inner class premise: An inner class must inherit a class or interface.
The format of the anonymous inner class:
new.父类或借口(){ 定义子类内容} 函数
- An anonymous inner class is an anonymous subclass object.
Class outer{Private Staticint x =3;Static class Inner { Static void function() {System.out.println ("inner:" +x)}}Static class Inner2 { voidShow () {System.out.println ("Inner2 Show")}} publicStatic voidMethod () {Inner.function(); New.inner2 (). Show (); }} class innerdemo{ Public Static voidMain (string[] args) {Outer.method (); }}
Dark Horse Programmer-object-oriented objects and inner classes