Java anonymous inner classes usually have no object variable points. It can only be used once
For example, the following code, to use the abstract class people eat also inherits and replicates the method eat way, very cumbersome. The same situation applies to interfaces as well.
Package com.lubby.nosynchronizedtest; Public Abstract class people {public abstract void Eat ();} <pre name= "code" class= "Java" >package Com.lubby.nosynchronizedtest;public class Teacher extends people {@ overridepublic void Eat () {System.out.println ("Teacher is Eating");} public static void Main (string[] args) {people people = new Teacher ();p eople.eat ();}}
Look at the following code for example. is not very easy. Between New one
Package Com.lubby.nosynchronizedtest;public class Teacher {public static void main (string[] args) {New people () {@Overrid epublic void Eat () {System.out.println ("I'm Eating");}. Eat ();}}
Look carefully. Discover whether threads are often used in such a way. Thread creation is generally inherited Threa abstract class or Runable interface
Package Com.lubby.nosynchronizedtest;public class Teacher {public static void main (string[] args) {Thread thread1 = new Th Read () {public void run () {System.out.println ("Thread 1 is Running");}}; Thread1.start ();}}
Package Com.lubby.nosynchronizedtest;public class Teacher {public static void main (string[] args) {Runnable runable = new Runnable () {@Overridepublic void run () {System.out.println ("Run ...");}; Thread thread = new Thread (runable); Thread.Start ();}}
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
Java Anonymous inner class