A cool guy who looks a little troublesome, but, it's still cool
/*
The advantage of anonymous inner class: one less class is defined
Disadvantage: cannot be reused
*/
public class fuck13{ //Static method public static void t(a a1){ a1.logout(); } public static void main(String[ ] args){ //t.(new b()); //Here we want to call the t method, here we use polymorphism //a a1=new b(), a new type b is created, which is automatically converted to type a //So it can be used as the actual parameter of the t method //The way of using an anonymous inner class //The whole new a(){```} is an anonymous inner class t(new a(){ public void logout(){// You can only inherit and then rewrite System.out.println("The program has exited safely");} } ); } } //Define an interface, the interface cannot create objects interface a{ void logout(); } /*class b implements a{ public void logout(){//Can only inherit and then rewrite System.out.println("The program has exited safely"); }
}*/