Anonymous inner class
1 Public InterfaceInter {}2 Interfaceinter2{3 voidShow ();4 }5 Main () {6 7 //error, interface cannot be instantiated8Inter T =NewInter ();9 Ten /*correctly, the object that creates the implementation class of the interface-implements the class omission (anonymous inner class), One * The contents of {} are equivalent to the member data in implementing Class aoo{} in the following statement . A * New Inter (...) {...} () for the corresponding constructor method parameter (if any) - */ -Inter T =NewInter (...) {...}; the -Inter2 x =NewInter2 () { - Public voidShow () {}//all method bodies within the interface (if any) must be implemented -};//note that the ";" Here Not less +X.show ();//implement the method body - } + A /* at The //upper statement is equivalent to the following notation, which is equivalent to omitting the aoo{} - Interface inter{} - class Aoo implements inter{...} - Main () { - Aoo t = new Aoo (); - } in */
Java-day15-nonameinner