the anonymous inner class implements two ways of threading:The first way:
1. Inheriting the thread class
2. Overriding the Run method
3. Write the code that will be executed in the Run method
The second way:
1. How to pass a subclass object of runnable to thread
2. Overriding the Run method
3. Write the executed code in the
the anonymous inner class implements two ways of threading:The first way:
1. Inheriting the thread class
2. Overriding the Run method
3. Write the code that will be executed in the Run method
The second way:
1. How to pass a subclass object of runnable to thread
2. Overriding the Run method
3. Write the executed code in the
1. What if someone asks you if the interface in Java can be new? I think the answer should be yes, when implementing an anonymous inner class.http://blog.csdn.net/cntanghai/article/details/60944812. If someone asks you if the class can be modified by private, I think the answer is yes, one of the benefits of the inner class
(NewRunnable () {7 @Override8 Public voidrun () {9 Try {TenThread.Sleep (50); One}Catch(interruptedexception e) { A e.printstacktrace (); - } - for(inti = 0; I ) the System.out.println (str); - } - }). Start (); - +System.out.println ("Main thread finished"); - } +}① Line 4th defines a local variable str in the Main method, line 6th defines a local inner class thre
Can be used directly:map{Put ("test1", "test11");Put ("Test2", "test11");}}; To initialize.In the online search, this is the use of anonymous classes in the way to initialize. The first layer {} is the definition of an anonymous class, and the second layer {} is the definition of the initialization function.But what is not figured out is that this should be an in
Java Collection frameworks such as set, map, and list do not provide any simple method for initialization. Each time a set is created, values must be added one by one. For example
CopyCode The Code is as follows: Set Letter. Add ('A ');
Letter. Add ('B ');
//...
Very tedious.
But use an anonymous internal class. It can be slightly simpler.
Copy code The Co
Basic theory:
-----------------------------------------------------
About Java Inner classes: an inner class is defined as a class that is defined within another class.
The reason for this exists is:
1. An object of an internal class can access the implementation of the obj
.
There are two types of nesting classes. One is static (modified with the static keyword), and the other is non-static, it is called an inner class ).
Note: in Think in Java, the author defines an internal class as "defining a class within the definition of another class, t
. println ("click, click");} public static void main (String [] args) {AnonymousInnerClass anonymousInnerClass = new AnonymousInnerClass (); anonymousInnerClass. click (new OnClickListener () {// directly new the anonymous internal class without saving the object. It is generally used to inherit other classes or implement the interface @ Overridepublic void onClick () {System. out. println ("Inner Click ");
First, ArraysFor the tool class for array manipulation, some methods for array sorting and binary searching are provided.Common methods:1. public static string toString (Int[] a): Converts an array of type int to a string.Converted to a string after the output form: ([element 1, Element 2, Element 3 ...]), arrays overrides the ToString method at the bottom.2, public static void sort (int[] a): Sorts the specified array of type int in ascending order o
Java internal class summary, java class Summary
Internal classes are not easy to understand, but to put it bluntly, a class also contains another class.
Just as a person is composed of the brain, limbs, organs, and other body resu
Advantage ⒈ the inner class object can access the implementation of the object that created it, including private data, ⒉ internal classes are not seen by other classes in the same package, and are well encapsulated, ⒊ can easily write event drivers using internal classes, and ⒋ anonymous inner classes can easily define runtime callbacks; 5. Internal classes can be easily defined
Java Basics-Stack and heap, static, final modifier, inner class, and Java memory allocation (RPM)Java Stack and heapHeap: Random in orderStack: LIFO (last-in/first-out).The Java heap is a run-time data area in which the objects of the cl
Original: http://www.javaworld.com/article/2077372/learn-java/static-class-declarations.htmlTo understand the use of the static keyword in a class declaration, we first need to understand the class declaration. There are two kinds, one is top-level class, the other is inner
Nested class does not depend on an instance object of an external class,static Nested class can access the non- static The member variable . 5. When you access staticnestedclass, You can direct use static Nestedclass , without the need to add the name of the outer class, in staticnestedclass static member va
. Some design and programming problems * are difficult to solve without the ability of an inner class to inherit multiple concrete or abstract classes. From this point of view, the inner class makes the solution of multiple inheritance complete. The interface solves some of the problems, while the inner classes effectively * implement multiple inheritance. "Java
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.