The inner class of the method is the inner class defined in the method of the outer class, and the inner class of the method can only be visible inside the method, that is, it can only be used inside the method
Features of the inner class of the method:
1. The object that creates the inner class of the method is the same as the static inner class ;
2. The inner class of the method cannot be used outside the method, so access control and static modifiers cannot be used;
1 Packagecom.imooc.test003;2 3 Public classOuter {4 5 Public voidTest () {6 7 intA = 10;8 9 //method inner class; access control and static modifiers cannot be usedTen classminner{ One A intb = 20; - - Public voidprint () { the -SYSTEM.OUT.PRINTLN ("Accessing constants in external class methods A:" +a); -SYSTEM.OUT.PRINTLN ("Variable B in the Access method inner class:" +b); - + } - + } A atMinner mi =NewMinner (); - mi.print (); - - } - - Public Static voidMain (string[] args) { inOuter in =NewOuter ();//to create an object of an inner class - in.test (); to } + -}View Code
Reference: MU-Class network (http://www.imooc.com/)
Method inner Classes in Java