Java Tour (ix)--object class, Equals,tostring,getclass, inner class access rule, static inner class, Inner class principle, anonymous inner class
Every day by some trivial hara
Java internal class (InnerClass) ---- non-static internal class, static internal class, local internal class, anonymous internal classMany people are not familiar with the java underwea
to write it as a separate class?The anonymous inner class is introduced at this time. Using an anonymous inner class implementation:1 Abstract classPerson {2 Public Abstract voideat ();3 }4 Public classDemo {5 Public Static voidMain (string[] args) {6 7
anonymous classes without the class keyword?1) to have the new operator, similar to the normal class instantiation of an expression.2) to implement an interface or inherit a class, the example above is to implement the HelloWorld interface.3) class body (body), where you ca
the name of the inner class is superfluous, soThe anonymous inner class is used.3, how to implement anonymous internal class? The implementation of an anonymous inner class is very si
1. A Java program is a collection of classes.A class in a program has two kinds of arrangement structures.
For example: classenclosingclass{.....
Class anestedclass{......}
}
2. In some special cases, a class is also placed within the internal definition of another class,
An anonymous internal class (an anonymous class is used to understand the function callback (this is not related to the thread) said: (the first Anonymous class is used to simplify the process.CodeInstead, it tells GC that this ob
Java Basics _ Inner classes: In Java, a class can be defined inside another class or inside a method, such that a class is called an inner class.The primary role of inner classes: using internal classes can reduce naming conflicts.Define location: An inner
; public void F () { System.out.println ("in Anonymous F ()"); } }; } public static void Main (string[] args) { base base = Anonymousconstructor.getbase (.); Base.F (); }}Nested ClassesA nested class is also a class defined in a class
its own properties and methods, but it cannot be instantiated because the parent class is instantiated, The parent class does not change the properties and methods in the anonymous class private String name = "AAA"; The {///anonymous cl
this class, and become the anonymous inner class.2, you will want to define a callback function, but do not want to write a lot of code, you can consider anonymous inner class.3. Syntax:Class outerclass{ //Peripheral class fie
corresponding object to invoke the interface, this process is called an interface callback for the object functionCross-class references1) If a is a reference to Class A, then a can point to an instance of Class A. Or the one that points to class ASub-class, which is a case
Class Object outside of if because it is beyond its scope. However, during compilation, the internal class trackingslip is compiled at the same time as other classes, except that it is in its own scope and is invalid if it exceeds this scope, it is no different from other internal classes.
Anonymous internal classThe syntax rules for
. Of course, the internal class defined in the method can diversify the design, and its purpose is not only in this regard. The following is a more strange example: Public class goods2 { Private void internaltracking (Boolean B ){ If (B ){ Class trackingslip { Private string ID; Trackingslip (string s ){ Id = s; } String getslip () {return ID ;} } Trac
achieve);2, when writing event-driven (the object of the inner class can access the member methods and variables of the external class, note including private members);3, in the case of the function can be achieved, in order to save the compilation of the resulting bytecode (internal classes can reduce the bytecode file, that is, the Java file compiled by the.
The Java inner class is divided into 4 sections, namely, overview, member inner class, local inner class, and anonymous inner class.In this article, the anonymous inner class of the
Anonymous inner class:1. Classes without class names are called anonymous inner classes2. Benefits: Simplified writing.3. Use premise: Must have the inheritance or the realization relation ... Don't think you have no money, you're not your father.4. Generally used for arguments. Focusclass outer{
When using a Java local inner class or an anonymous inner class, the local variable must be decorated with the final keyword if the class invokes a local variable of the method, or a compilation error will occur "cannot refer to a non-final variable * inside an Inner
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.