Anonymous internal class:
1. Anonymous internal classes are actually the abbreviation format of internal classes.
2. Prerequisites for defining anonymous internal classes:
The inner class must inherit a class or implement an interface.
3. The format of anonymous internal class: new parent class or interface (){define the content of the subclass}
4. In fact, an anonymous internal class is an anonymous subclass object. And this object is a bit fat. It can be understood as an object with content.
5. It is best not to have more than 3 methods defined in anonymous internal classes.
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(); 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(); }}The above cliché talk about the anonymous internal class of Java is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.