Java internal category points

xiaoxiao2021-03-06  38

Internal class 1. Static class has a variety of control petitioners: private, public, protected, packed2. Class-class member default access control is Package, and the default access control of the method variable is private, and cannot be added to the control . External categories can only have two access modifiers: public or default is Package3. The internal class can be any modifier, in fact, the internal class is a member of its external class, and its access modifier determines whether it can be outside class visibility of objects, the default class object is to establish internal package4: outerObject = new outerClass (Constructor Parameters); outerClass.innerClass innerObject = outerObject.new InnerClass (Constructor Parameters); 5 internal class limits not departing from the class external use only. It is necessary for OuterClass.INNERCLASS INNEROBJECT so use. 6. Java Compiler When creating an internal class object, implicitly introduced the reference to the external class object into and saved. This allows the internal class object to always access its external class object, and this is why the external class object must be created in the external class scope must first create the reason why the external class object is created. Internal class objects can access any variables or methods of external classes (including private variables or methods) 7. The member variables of the parties have been blocked, what should I do? Nothing, Java expresses the reference to the external class in Java: OuterClass.this8. Compared to the non-static internal class, the difference is that the static internal class does not point to the external reference, in any non-static internal class, You can't have static data, static methods or yet a static internal class (nesting of the internal class can be more than one layer). However, the static internal class can have all this. This is also the second difference between the two. 9. Local internal classes: Define within a method or even a block. ** It has its own scope, which is ineffective exceeds this range, and there is no difference between it and other internal classes. When the internal class is defined in the block, for the block, only the final type variable containing the block containing it is, but there is no limit to the external class attribute. 10. Anonymous internal class: New dog () {} 11. The most external internal class is: **** The internal class is accessible to all contents of the external class, so it can participate in the external class Method is calculated. And internal classes can also be implemented in other interfaces or classes, so that internal classes can be regarded as a class method that is enlarged.

12. Define the internal class in the method body, only the local variable defined in the method is available. Cause: The variable defined in the method body will die with the method of exiting, by defining its Final variable It can be extended to expand its lifetime, can be combined with the life-actions to access their class instance, because the life of the class instance is different from the method and its own variable, which is automatically controlled by the system, but the access to class properties is not strict. limit. 13. The local variable defined by Final is equivalent to a constant, and its life cycle is outside the method body. 14. Because class B is the internal class of class A, class C is another internal class of class B, so class C is also the internal class of class A.

转载请注明原文地址:https://www.9cbs.com/read-55199.html

New Post(0)