An anonymous java internal class is generally an object without a variable pointing to. It can only be used once.
The following code is very troublesome to inherit and rewrite the eat method to use the eat method of the abstract class People. This is also true for interfaces.
Package com. lubby. nosynchronizedtest; public abstract class People {public abstract void eat ();}Package com. lubby. nosynchronizedtest; public class Teacher extends People {@ Overridepublic void eat () {System. out. println ("the instructor is eating");} public static void main (String [] args) {People people = new Teacher (); people. eat ();}}
Check the following code. Between new
Package com. lubby. nosynchronizedtest; public class Teacher {public static void main (String [] args) {new People () {@ Overridepublic void eat () {System. out. println ("I'm eating ");}}. eat ();}}
Take a closer look and find out if this method is frequently used by threads. Generally, thread creation inherits the Threa abstract class or Runable interface.
Package com. lubby. nosynchronizedtest; public class Teacher {public static void main (String [] args) {Thread thread1 = new Thread () {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();}}