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 Run method, and finally we open the thread
PackageCom.yyx.thread;/*** Anonymous inner class create thread Yyx February 4, 2018*/ Public classAnonymousthread { Public Static voidMain (string[] args) {//inheriting the thread class for multithreading NewThread () { Public voidrun () { for(intx = 0; x < 50; X + +) {System.out.println (Thread.CurrentThread (). GetName ()+ "--" +x); }}}.start (); //implement runnable excuses, create multithreading and start NewThread (NewRunnable () {@Override Public voidrun () { for(intx = 0; x < 50; X + +) {System.out.println (Thread.CurrentThread (). GetName ()+ "--" +x); }}}) {}.start (); }}
The Java multithreaded thread is created using anonymous inner classes in two ways