Java anonymous internal class, java Anonymous
/*
Anonymous internal class:
1. The anonymous internal class is in short format.
2. Prerequisites for defining anonymous internal classes:
An internal class must inherit a class or implement an interface.
3. Format of the anonymous internal class: new parent class or interface () {defines the content of the subclass}
4. In fact, an anonymous internal class is an anonymous subclass object. And the object is a little fat. It can be understood as an object with content.
5. It is recommended that no more than three methods are defined in the anonymous internal class.
*/
Abstract class AbsDemo {abstract void show ();} class Outer {int x = 3;/* class Inner extends AbsDemo {int num = 90; void show () {System. out. println ("show:" + num);} void abc () {System. out. println ("hehe") ;}} */public void function () {// AbsDemo a = new Inner (); // Inner in = new Inner (); // in. show (); // in. abc (); AbsDemo d = new AbsDemo () {int num = 9; void show () {System. out. println ("num =" + num);} void abc () {System. out. println ("haha") ;}}; d. show (); // d. abc (); // compilation failed;} class InnerClassDemo4 {public static void main (String [] args) {new Outer (). function ();}}